mirror of https://github.com/2dust/v2rayN
Copy the bin folder to the storage location (for init)
parent
0953237e9e
commit
54fe669d89
|
@ -156,7 +156,7 @@ namespace ServiceLib.Common
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CopyDirectory(string sourceDir, string destinationDir, bool recursive, string? ignoredName)
|
public static void CopyDirectory(string sourceDir, string destinationDir, bool recursive, bool overwrite, string? ignoredName = null)
|
||||||
{
|
{
|
||||||
// Get information about the source directory
|
// Get information about the source directory
|
||||||
var dir = new DirectoryInfo(sourceDir);
|
var dir = new DirectoryInfo(sourceDir);
|
||||||
|
@ -183,7 +183,11 @@ namespace ServiceLib.Common
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var targetFilePath = Path.Combine(destinationDir, file.Name);
|
var targetFilePath = Path.Combine(destinationDir, file.Name);
|
||||||
file.CopyTo(targetFilePath, true);
|
if (!overwrite && File.Exists(targetFilePath))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
file.CopyTo(targetFilePath, overwrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If recursive and copying subdirectories, recursively call this method
|
// If recursive and copying subdirectories, recursively call this method
|
||||||
|
@ -192,7 +196,7 @@ namespace ServiceLib.Common
|
||||||
foreach (var subDir in dirs)
|
foreach (var subDir in dirs)
|
||||||
{
|
{
|
||||||
var newDestinationDir = Path.Combine(destinationDir, subDir.Name);
|
var newDestinationDir = Path.Combine(destinationDir, subDir.Name);
|
||||||
CopyDirectory(subDir.FullName, newDestinationDir, true, ignoredName);
|
CopyDirectory(subDir.FullName, newDestinationDir, true, overwrite, ignoredName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -519,7 +519,7 @@ namespace ServiceLib.Common
|
||||||
|
|
||||||
public static bool UpgradeAppExists(out string upgradeFileName)
|
public static bool UpgradeAppExists(out string upgradeFileName)
|
||||||
{
|
{
|
||||||
upgradeFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GetExeName("AmazTool"));
|
upgradeFileName = Path.Combine(GetBaseDirectory(), GetExeName("AmazTool"));
|
||||||
return File.Exists(upgradeFileName);
|
return File.Exists(upgradeFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -666,12 +666,12 @@ namespace ServiceLib.Common
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//When this file exists, it is equivalent to having no permission to read and write
|
//When this file exists, it is equivalent to having no permission to read and write
|
||||||
if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "NotStoreConfigHere.txt")))
|
if (File.Exists(Path.Combine(GetBaseDirectory(), "NotStoreConfigHere.txt")))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "guiTemps");
|
var tempPath = Path.Combine(GetBaseDirectory(), "guiTemps");
|
||||||
if (!Directory.Exists(tempPath))
|
if (!Directory.Exists(tempPath))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(tempPath);
|
Directory.CreateDirectory(tempPath);
|
||||||
|
@ -699,6 +699,11 @@ namespace ServiceLib.Common
|
||||||
return Path.Combine(startupPath, fileName);
|
return Path.Combine(startupPath, fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetBaseDirectory(string fileName = "")
|
||||||
|
{
|
||||||
|
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
public static string GetExePath()
|
public static string GetExePath()
|
||||||
{
|
{
|
||||||
return Environment.ProcessPath ?? Process.GetCurrentProcess().MainModule?.FileName ?? string.Empty;
|
return Environment.ProcessPath ?? Process.GetCurrentProcess().MainModule?.FileName ?? string.Empty;
|
||||||
|
@ -706,12 +711,12 @@ namespace ServiceLib.Common
|
||||||
|
|
||||||
public static string StartupPath()
|
public static string StartupPath()
|
||||||
{
|
{
|
||||||
if (Utils.IsNonWindows() && Environment.GetEnvironmentVariable(Global.LocalAppData) == "1")
|
if (Environment.GetEnvironmentVariable(Global.LocalAppData) == "1")
|
||||||
{
|
{
|
||||||
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "v2rayN");
|
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "v2rayN");
|
||||||
}
|
}
|
||||||
|
|
||||||
return AppDomain.CurrentDomain.BaseDirectory;
|
return GetBaseDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetTempPath(string filename = "")
|
public static string GetTempPath(string filename = "")
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
|
|
||||||
public bool InitApp()
|
public bool InitApp()
|
||||||
{
|
{
|
||||||
if (Utils.IsNonWindows() && Utils.HasWritePermission() == false)
|
if (Utils.HasWritePermission() == false)
|
||||||
{
|
{
|
||||||
Environment.SetEnvironmentVariable(Global.LocalAppData, "1", EnvironmentVariableTarget.Process);
|
Environment.SetEnvironmentVariable(Global.LocalAppData, "1", EnvironmentVariableTarget.Process);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,17 @@ namespace ServiceLib.Handler
|
||||||
Environment.SetEnvironmentVariable(Global.V2RayLocalAsset, Utils.GetBinPath(""), EnvironmentVariableTarget.Process);
|
Environment.SetEnvironmentVariable(Global.V2RayLocalAsset, Utils.GetBinPath(""), EnvironmentVariableTarget.Process);
|
||||||
Environment.SetEnvironmentVariable(Global.XrayLocalAsset, Utils.GetBinPath(""), EnvironmentVariableTarget.Process);
|
Environment.SetEnvironmentVariable(Global.XrayLocalAsset, Utils.GetBinPath(""), EnvironmentVariableTarget.Process);
|
||||||
|
|
||||||
|
//Copy the bin folder to the storage location (for init)
|
||||||
|
if (Environment.GetEnvironmentVariable(Global.LocalAppData) == "1")
|
||||||
|
{
|
||||||
|
var fromPath = Utils.GetBaseDirectory("bin");
|
||||||
|
var toPath = Utils.GetBinPath("");
|
||||||
|
if (fromPath != toPath)
|
||||||
|
{
|
||||||
|
FileManager.CopyDirectory(fromPath, toPath, true, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Utils.IsNonWindows())
|
if (Utils.IsNonWindows())
|
||||||
{
|
{
|
||||||
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo();
|
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo();
|
||||||
|
|
|
@ -173,7 +173,7 @@ namespace ServiceLib.ViewModels
|
||||||
var configDirZipTemp = Utils.GetTempPath($"v2rayN_{DateTime.Now:yyyyMMddHHmmss}");
|
var configDirZipTemp = Utils.GetTempPath($"v2rayN_{DateTime.Now:yyyyMMddHHmmss}");
|
||||||
var configDirTemp = Path.Combine(configDirZipTemp, _guiConfigs);
|
var configDirTemp = Path.Combine(configDirZipTemp, _guiConfigs);
|
||||||
|
|
||||||
FileManager.CopyDirectory(configDir, configDirTemp, false, "cache.db");
|
FileManager.CopyDirectory(configDir, configDirTemp, false, true, "cache.db");
|
||||||
var ret = FileManager.CreateFromDirectory(configDirZipTemp, fileName);
|
var ret = FileManager.CreateFromDirectory(configDirZipTemp, fileName);
|
||||||
Directory.Delete(configDirZipTemp, true);
|
Directory.Delete(configDirZipTemp, true);
|
||||||
return await Task.FromResult(ret);
|
return await Task.FromResult(ret);
|
||||||
|
|
|
@ -248,7 +248,7 @@ namespace ServiceLib.ViewModels
|
||||||
{
|
{
|
||||||
foreach (var subDir in dir.GetDirectories())
|
foreach (var subDir in dir.GetDirectories())
|
||||||
{
|
{
|
||||||
FileManager.CopyDirectory(subDir.FullName, toPath, false, null);
|
FileManager.CopyDirectory(subDir.FullName, toPath, false, true);
|
||||||
subDir.Delete(true);
|
subDir.Delete(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue