Skip to content

Commit

Permalink
Fixed some issues
Browse files Browse the repository at this point in the history
1. OutOfMemory exception
2. Wrong icon
3. Registry integration
  • Loading branch information
zanybaka committed Aug 26, 2020
1 parent 8acdc55 commit 35ff61d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
Binary file modified build/v2.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Console.v2/Console.v2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>FileLockedBy2</AssemblyName>
<RootNamespace>FileLockedBy</RootNamespace>
<ApplicationIcon>unlock-128.ico</ApplicationIcon>
<ApplicationIcon>unlock-64.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/Console.v2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ static void Main(string[] args)
int handleCount = information.Count;
var process = Process.GetProcessById(info.Process.dwProcessId);
var infoEnumerator = ProcessHelper.GetCurrentProcessOpenFilesEnumerator(info.Process.dwProcessId, sptr, handleCount);
while (infoEnumerator.MoveNext())
bool skip = false;
while (infoEnumerator.MoveNext() && !skip)
{
FileHandleInfo current = infoEnumerator.Current;
if (string.Compare(path, current.FileSystemInfo.FullName, StringComparison.OrdinalIgnoreCase) != 0) continue;
Console.WriteLine($"Found! {process.ProcessName} -> {process.MainModule.FileName}");
found = true;
skip = true;
var result = ProcessHelper.CloseHandle(process, current, currentProcess);
Console.WriteLine(result == 0 ? "Success." : $"Error: {Enum.GetName(typeof(Error), result)}");
}
Expand Down
4 changes: 3 additions & 1 deletion src/Console.v2/Registry/ExplorerIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public static void RegisterMenuItem(string app, string path)
throw new NotSupportedException("The platform is not supported.");
}

RegistryKey shell = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Classes\\*\\shell", writable: true);
RegistryKey classes = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Classes", writable: true);
RegistryKey asterisk = classes.OpenSubKey("*", writable: true) ?? classes.CreateSubKey("*");
RegistryKey shell = asterisk.OpenSubKey("shell", writable: true) ?? asterisk.CreateSubKey("shell");
RegistryKey unlock = shell.CreateSubKey(app, writable: true);
unlock.SetValue("Icon", $"\"{path}\"");
RegistryKey command = unlock.CreateSubKey("command");
Expand Down

0 comments on commit 35ff61d

Please sign in to comment.