mirror of
https://github.com/2dust/v2rayN.git
synced 2025-04-20 06:02:23 +00:00
Restore backup file check
This commit is contained in:
parent
8505f2db96
commit
ff6716b39d
6 changed files with 49 additions and 3 deletions
|
@ -102,6 +102,24 @@ namespace ServiceLib.Common
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<string>? GetFilesFromZip(string fileName)
|
||||||
|
{
|
||||||
|
if (!File.Exists(fileName))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using ZipArchive archive = ZipFile.OpenRead(fileName);
|
||||||
|
return archive.Entries.Select(entry => entry.FullName).ToList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(ex.Message, ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static bool CreateFromDirectory(string sourceDirectoryName, string destinationArchiveFileName)
|
public static bool CreateFromDirectory(string sourceDirectoryName, string destinationArchiveFileName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
9
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
9
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
|
@ -321,6 +321,15 @@ namespace ServiceLib.Resx {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 Invalid backup file 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
public static string LocalRestoreInvalidZipTips {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("LocalRestoreInvalidZipTips", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Address 的本地化字符串。
|
/// 查找类似 Address 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -1315,4 +1315,7 @@
|
||||||
<data name="LvWebDavDirName" xml:space="preserve">
|
<data name="LvWebDavDirName" xml:space="preserve">
|
||||||
<value>Remote folder name (optional)</value>
|
<value>Remote folder name (optional)</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="LocalRestoreInvalidZipTips" xml:space="preserve">
|
||||||
|
<value>Invalid backup file</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -1312,4 +1312,7 @@
|
||||||
<data name="LvWebDavDirName" xml:space="preserve">
|
<data name="LvWebDavDirName" xml:space="preserve">
|
||||||
<value>远程文件夹名称(可选)</value>
|
<value>远程文件夹名称(可选)</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="LocalRestoreInvalidZipTips" xml:space="preserve">
|
||||||
|
<value>无效备份文件</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -1192,4 +1192,7 @@
|
||||||
<data name="LvWebDavDirName" xml:space="preserve">
|
<data name="LvWebDavDirName" xml:space="preserve">
|
||||||
<value>遠端資料夾名稱(可選)</value>
|
<value>遠端資料夾名稱(可選)</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="LocalRestoreInvalidZipTips" xml:space="preserve">
|
||||||
|
<value>無效備份文件</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -7,6 +7,9 @@ namespace ServiceLib.ViewModels
|
||||||
{
|
{
|
||||||
public class BackupAndRestoreViewModel : MyReactiveObject
|
public class BackupAndRestoreViewModel : MyReactiveObject
|
||||||
{
|
{
|
||||||
|
private readonly string _guiConfigs = "guiConfigs";
|
||||||
|
private static string BackupFileName => $"backup_{DateTime.Now:yyyyMMddHHmmss}.zip";
|
||||||
|
|
||||||
public ReactiveCommand<Unit, Unit> RemoteBackupCmd { get; }
|
public ReactiveCommand<Unit, Unit> RemoteBackupCmd { get; }
|
||||||
public ReactiveCommand<Unit, Unit> RemoteRestoreCmd { get; }
|
public ReactiveCommand<Unit, Unit> RemoteRestoreCmd { get; }
|
||||||
public ReactiveCommand<Unit, Unit> WebDavCheckCmd { get; }
|
public ReactiveCommand<Unit, Unit> WebDavCheckCmd { get; }
|
||||||
|
@ -65,7 +68,7 @@ namespace ServiceLib.ViewModels
|
||||||
private async Task RemoteBackup()
|
private async Task RemoteBackup()
|
||||||
{
|
{
|
||||||
DisplayOperationMsg();
|
DisplayOperationMsg();
|
||||||
var fileName = Utils.GetBackupPath($"backup_{DateTime.Now:yyyyMMddHHmmss}.zip");
|
var fileName = Utils.GetBackupPath(BackupFileName);
|
||||||
var result = await CreateZipFileFromDirectory(fileName);
|
var result = await CreateZipFileFromDirectory(fileName);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
|
@ -122,9 +125,16 @@ namespace ServiceLib.ViewModels
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//check
|
||||||
|
var lstFiles = FileManager.GetFilesFromZip(fileName);
|
||||||
|
if (lstFiles is null || !lstFiles.Where(t => t.Contains(_guiConfigs)).Any())
|
||||||
|
{
|
||||||
|
DisplayOperationMsg(ResUI.LocalRestoreInvalidZipTips);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//backup first
|
//backup first
|
||||||
var fileBackup = Utils.GetBackupPath($"backup_{DateTime.Now:yyyyMMddHHmmss}.zip");
|
var fileBackup = Utils.GetBackupPath(BackupFileName);
|
||||||
var result = await CreateZipFileFromDirectory(fileBackup);
|
var result = await CreateZipFileFromDirectory(fileBackup);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
|
@ -145,7 +155,7 @@ namespace ServiceLib.ViewModels
|
||||||
|
|
||||||
var configDir = Utils.GetConfigPath();
|
var configDir = Utils.GetConfigPath();
|
||||||
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);
|
||||||
|
|
||||||
await Task.Run(() => FileManager.CopyDirectory(configDir, configDirTemp, false, "cache.db"));
|
await Task.Run(() => FileManager.CopyDirectory(configDir, configDirTemp, false, "cache.db"));
|
||||||
var ret = await Task.Run(() => FileManager.CreateFromDirectory(configDirZipTemp, fileName));
|
var ret = await Task.Run(() => FileManager.CreateFromDirectory(configDirZipTemp, fileName));
|
||||||
|
|
Loading…
Reference in a new issue