Skip to content

Commit

Permalink
解决低版本写入不同的注册表无法识别路径的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
NotFaceGUI committed Oct 17, 2022
1 parent 92759d5 commit 5d99e84
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions AsepriteReadTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ private static string GetAseRegFileOpenWithPath()
var value = ((string)software?.GetValue(""))?.Replace("\"", "").Replace("%1", "").TrimEnd();
return value;
}
}
}

35 changes: 26 additions & 9 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace QuickLook.Plugin.AsepriteViewer
public class Plugin : IViewer
{
public static string ExePath;
public static bool NotFound;

private readonly string[] _formats = { ".ase", ".aseprite" };
private readonly string _tempPath = Path.GetTempPath() + "quick-look-ase";
Expand All @@ -34,7 +35,6 @@ public class Plugin : IViewer
private ImagePanel _image;
private MetaProvider _meta;

private bool _notFound;

public int Priority => 0;

Expand All @@ -44,15 +44,26 @@ public void Init()
Directory.CreateDirectory(_tempPath);

ExePath = GetAseRegFileOpenWithPath();

if (ExePath != default) return;

foreach (var exeSparePath in _exeSparePaths)
{
if (File.Exists(exeSparePath))
ExePath = exeSparePath;
}

var tempPathConfig = _tempPath + "/config";
if (File.Exists(tempPathConfig))
{
var readLines = File.ReadLines(tempPathConfig);
foreach (var readLine in readLines)
ExePath = readLine;
}
else
File.Create(tempPathConfig);
if (ExePath == default)
_notFound = true;
NotFound = true;
}

public bool CanHandle(string path)
Expand All @@ -62,18 +73,18 @@ public bool CanHandle(string path)

public void Prepare(string path, ContextObject context)
{
if (!Directory.Exists(_tempPath))
Directory.CreateDirectory(_tempPath);

if (_notFound)

if (NotFound)
{
context.PreferredSize = new Size { Width = 600, Height = 400 };
}
else
{
var fileName = Path.GetFileName(path);
var tempPath = Path.GetTempPath() + "quick-look-ase";

if (!Directory.Exists(tempPath))
Directory.CreateDirectory(tempPath);
var fileInfo = new FileInfo(path);
var fileInfoLastWriteTime = fileInfo.LastWriteTime;

Expand Down Expand Up @@ -103,6 +114,7 @@ public void Prepare(string path, ContextObject context)
cmdProcess.Start();
cmdProcess.WaitForExit();
cmdProcess.Close();

}

_meta = new MetaProvider(_imagePath);
Expand All @@ -118,9 +130,9 @@ public void Prepare(string path, ContextObject context)

public void View(string path, ContextObject context)
{
if (_notFound)
if (NotFound)
{
var viewer = new Label { Content = "default open with?" };
var viewer = new Label { Content = "default open with?\nplan A: Set default open with \nplan B: open %temp%\\quick-look-ase\nmodify config file Add the path of your Aseprite.exe" };

context.ViewerContent = viewer;
context.Title = $"{Path.GetFileName(path)}";
Expand Down Expand Up @@ -161,7 +173,12 @@ private string GetAseRegFileOpenWithPath()
var classesRoot = Registry.ClassesRoot;
var software = classesRoot.OpenSubKey("AsepriteFile\\shell\\open\\command");
if (software == null)
return default;
{
software = classesRoot.OpenSubKey("aseprite_auto_file\\shell\\open\\command");
if (software == null)
return default;
}

var value = ((string)software.GetValue(""))?.Replace("\"", "").Replace("%1", "").TrimEnd();
return value;
}
Expand Down
1 change: 0 additions & 1 deletion QuickLook.Plugin.AsepriteViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
<Compile Include="AseRead\AseBuffer.cs" />
<Compile Include="AseRead\AsepriteFile.cs" />
<Compile Include="AseRead\AseReadFile.cs" />
<Compile Include="GitVersion.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down

0 comments on commit 5d99e84

Please sign in to comment.