mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-16 21:32:39 +00:00
Fix #731: use app folder for saving data in the portable mode
This commit is contained in:
Submodule QuickLook.Common updated: 5c035caf52...4ea4cfc971
@@ -39,8 +39,9 @@ namespace QuickLook
|
||||
public static readonly bool IsUWP = ProcessHelper.IsRunningAsUWP();
|
||||
public static readonly bool IsWin10 = Environment.OSVersion.Version >= new Version(10, 0);
|
||||
public static readonly bool IsGPUInBlacklist = SystemHelper.IsGPUInBlacklist();
|
||||
public static readonly bool IsPortable = SettingHelper.IsPortableVersion();
|
||||
|
||||
private bool _isFirstInstance;
|
||||
private bool _cleanExit;
|
||||
private Mutex _isRunning;
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
@@ -55,26 +56,11 @@ namespace QuickLook
|
||||
|
||||
private void Application_Startup(object sender, StartupEventArgs e)
|
||||
{
|
||||
if (ProcessHelper.IsOnWindows10S())
|
||||
if (!EnsureOSVersion()
|
||||
|| !EnsureFirstInstance(e.Args)
|
||||
|| !EnsureFolderWritable(SettingHelper.LocalDataPath))
|
||||
{
|
||||
MessageBox.Show("This application does not run on Windows 10 S.");
|
||||
|
||||
Shutdown();
|
||||
return;
|
||||
}
|
||||
|
||||
EnsureFirstInstance();
|
||||
|
||||
if (!_isFirstInstance)
|
||||
{
|
||||
// second instance: preview this file
|
||||
if (e.Args.Any() && (Directory.Exists(e.Args.First()) || File.Exists(e.Args.First())))
|
||||
RemoteCallShowPreview(e);
|
||||
// second instance: duplicate
|
||||
else
|
||||
MessageBox.Show(TranslationHelper.Get("APP_SECOND_TEXT"), TranslationHelper.Get("APP_SECOND"),
|
||||
MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
|
||||
_cleanExit = false;
|
||||
Shutdown();
|
||||
return;
|
||||
}
|
||||
@@ -84,7 +70,35 @@ namespace QuickLook
|
||||
|
||||
// first instance: run and preview this file
|
||||
if (e.Args.Any() && (Directory.Exists(e.Args.First()) || File.Exists(e.Args.First())))
|
||||
RemoteCallShowPreview(e);
|
||||
PipeServerManager.SendMessage(PipeMessages.Toggle, e.Args.First());
|
||||
}
|
||||
|
||||
private bool EnsureOSVersion()
|
||||
{
|
||||
if (!ProcessHelper.IsOnWindows10S())
|
||||
return true;
|
||||
|
||||
MessageBox.Show("This application does not run on Windows 10 S.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool EnsureFolderWritable(string folder)
|
||||
{
|
||||
try
|
||||
{
|
||||
var path = FileHelper.CreateTempFile(folder);
|
||||
File.Delete(path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show(string.Format(TranslationHelper.Get("APP_PATH_NOT_WRITABLE"), folder), "QuickLook",
|
||||
MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckUpdate()
|
||||
@@ -96,11 +110,6 @@ namespace QuickLook
|
||||
SettingHelper.Set("LastUpdateTicks", DateTime.Now.Ticks);
|
||||
}
|
||||
|
||||
private void RemoteCallShowPreview(StartupEventArgs e)
|
||||
{
|
||||
PipeServerManager.SendMessage(PipeMessages.Toggle, e.Args.First());
|
||||
}
|
||||
|
||||
private void RunListener(StartupEventArgs e)
|
||||
{
|
||||
TrayIconManager.GetInstance();
|
||||
@@ -119,7 +128,7 @@ namespace QuickLook
|
||||
|
||||
private void App_OnExit(object sender, ExitEventArgs e)
|
||||
{
|
||||
if (!_isFirstInstance)
|
||||
if (!_cleanExit)
|
||||
return;
|
||||
|
||||
_isRunning.ReleaseMutex();
|
||||
@@ -130,9 +139,24 @@ namespace QuickLook
|
||||
ViewWindowManager.GetInstance().Dispose();
|
||||
}
|
||||
|
||||
private void EnsureFirstInstance()
|
||||
private bool EnsureFirstInstance(string[] args)
|
||||
{
|
||||
_isRunning = new Mutex(true, "QuickLook.App.Mutex", out _isFirstInstance);
|
||||
_isRunning = new Mutex(true, "QuickLook.App.Mutex", out bool isFirst);
|
||||
|
||||
if (isFirst)
|
||||
return true;
|
||||
|
||||
// second instance: preview this file
|
||||
if (args.Any() && (Directory.Exists(args.First()) || File.Exists(args.First())))
|
||||
{
|
||||
PipeServerManager.SendMessage(PipeMessages.Toggle, args.First());
|
||||
}
|
||||
// second instance: duplicate
|
||||
else
|
||||
MessageBox.Show(TranslationHelper.Get("APP_SECOND_TEXT"), TranslationHelper.Get("APP_SECOND"),
|
||||
MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -153,6 +153,7 @@
|
||||
<APP_START>QuickLook is running in the background.</APP_START>
|
||||
<APP_SECOND>QuickLook is already running</APP_SECOND>
|
||||
<APP_SECOND_TEXT>QuickLook enables quick previewing of certain type of files by pressing the spacebar while it is highlighted.</APP_SECOND_TEXT>
|
||||
<APP_PATH_NOT_WRITABLE>Data path "{0}" is not writable. Please check if you have sufficient premission.</APP_PATH_NOT_WRITABLE>
|
||||
<MW_BrowseFolder>Browse {0}</MW_BrowseFolder>
|
||||
<MW_Open>Open {0}</MW_Open>
|
||||
<MW_OpenWith>Open with {0}</MW_OpenWith>
|
||||
@@ -489,6 +490,7 @@
|
||||
<APP_START>QuickLook 正在后台运行。</APP_START>
|
||||
<APP_SECOND>另一个 QuickLook 进程正在运行</APP_SECOND>
|
||||
<APP_SECOND_TEXT>在您选中文件并按下空格键时,QuickLook 将提供多种格式的快速预览。</APP_SECOND_TEXT>
|
||||
<APP_PATH_NOT_WRITABLE>数据目录 "{0}" 不可写。请检查您是否有足够的权限。</APP_PATH_NOT_WRITABLE>
|
||||
<MW_BrowseFolder>浏览 {0}</MW_BrowseFolder>
|
||||
<MW_Open>打开 {0}</MW_Open>
|
||||
<MW_OpenWith>用 {0} 打开</MW_OpenWith>
|
||||
@@ -514,6 +516,7 @@
|
||||
<APP_START>QuickLook 正在背景執行</APP_START>
|
||||
<APP_SECOND>另一個 QuickLook 處理程序正在執行。</APP_SECOND>
|
||||
<APP_SECOND_TEXT>在資料夾中選取任意檔案並按下空白鍵,QuickLook 即可提供多種檔案格式的快速預覽。</APP_SECOND_TEXT>
|
||||
<APP_PATH_NOT_WRITABLE>數據目錄 "{0}" 不可寫。請檢查您是否有足夠的權限。</APP_PATH_NOT_WRITABLE>
|
||||
<MW_BrowseFolder>瀏覽 {0}</MW_BrowseFolder>
|
||||
<MW_Open>開啟 {0}</MW_Open>
|
||||
<MW_OpenWith>使用 {0} 開啟</MW_OpenWith>
|
||||
|
@@ -2,5 +2,9 @@ $version = git describe --always --tags
|
||||
|
||||
Start-Sleep -s 1
|
||||
|
||||
Write-Output "This file makes QuickLook portable." >> ..\Build\Package\portable.lock
|
||||
|
||||
Remove-Item ..\Build\QuickLook-$version.zip -ErrorAction SilentlyContinue
|
||||
Compress-Archive ..\Build\Package\* ..\Build\QuickLook-$version.zip
|
||||
Compress-Archive ..\Build\Package\* ..\Build\QuickLook-$version.zip
|
||||
|
||||
Remove-Item ..\Build\Package\portable.lock
|
Reference in New Issue
Block a user