#354, add command option -restore_snapshot "[0-9a-z]"

This commit is contained in:
Kang Yu 2025-02-02 11:58:06 -08:00
parent 5a794baf8b
commit 0e622b8021
2 changed files with 39 additions and 1 deletions

View file

@ -567,6 +567,28 @@ namespace PersistentWindows.Common
}
public void RestoreSnapshotCmd(int id)
{
string productName = System.Windows.Forms.Application.ProductName;
appDataFolder = redirectAppDataFolder ? "." :
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), productName);
#if DEBUG
//avoid db path conflict with release version
//appDataFolder = ".";
appDataFolder = AppDomain.CurrentDomain.BaseDirectory;
#endif
ReadDataDumpSafe();
curDisplayKey = GetDisplayKey();
CaptureNewDisplayConfig(curDisplayKey);
//RestoreSnapshot(id);
restoringSnapshot = true;
snapshotId = id;
restoringFromMem = true;
RestoreApplicationsOnCurrentDisplays(curDisplayKey, IntPtr.Zero, DateTime.Now);
}
public bool Start(bool auto_restore_from_db, bool auto_restore_last_capture_at_startup)
{
process = Process.GetCurrentProcess();
@ -2971,7 +2993,8 @@ namespace PersistentWindows.Common
//vacantDeskWindow = User32.FindWindowEx(vacantDeskWindow, IntPtr.Zero, "SHELLDLL_DefView", "");
//vacantDeskWindow = User32.FindWindowEx(vacantDeskWindow, IntPtr.Zero, "SysListView32", "FolderView");
//show icon on taskbar
hideRestoreTip();
if (hideRestoreTip != null)
hideRestoreTip();
}
continue;
}

View file

@ -82,6 +82,7 @@ if not errorlevel 1 goto wait_to_finish";
bool auto_upgrade = false;
bool legacy_icon = false;
bool waiting_taskbar = false;
int restore_snapshot = -1;
foreach (var arg in args)
{
@ -137,6 +138,11 @@ if not errorlevel 1 goto wait_to_finish";
hotkey = arg[0];
continue;
}
else if (restore_snapshot != -1)
{
restore_snapshot = SnapshotCharToId(arg[0]);
continue;
}
switch(arg)
{
@ -287,9 +293,18 @@ if not errorlevel 1 goto wait_to_finish";
case "-dump_window_pos_at_exit=0":
pwp.dumpDataWhenExit = false;
break;
case "-restore_snapshot":
restore_snapshot = 0;
break;
}
}
if (restore_snapshot >= 0)
{
pwp.RestoreSnapshotCmd(restore_snapshot);
return;
}
string productName = System.Windows.Forms.Application.ProductName;
string appDataFolder = redirect_appdata ? "." :
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),