mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
ËxtensionManager: Added IsAssociationOutdated function
This commit is contained in:
parent
746837cf26
commit
c676aed591
@ -15,18 +15,51 @@ namespace Wabbajack.Common
|
||||
private static readonly string AppRegPath = "Software\\Classes\\Applications\\Wabbajack.exe";
|
||||
private static readonly string AppAssocRegPath =
|
||||
$"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\{Extension}";
|
||||
private static readonly string Win8RegPath = $"Software\\Classes\\{Extension.Replace(".", "")}_auto_file";
|
||||
|
||||
public static bool IsExtensionAssociated()
|
||||
{
|
||||
return (Registry.CurrentUser.OpenSubKey(AppAssocRegPath, false) == null);
|
||||
}
|
||||
|
||||
public static void AssociateExtension(string iconPath, string appPath)
|
||||
private static bool IsWin8()
|
||||
{
|
||||
var winVersion = new Version(6, 2, 9200, 0);
|
||||
return (Environment.OSVersion.Platform >= PlatformID.Win32NT &&
|
||||
Environment.OSVersion.Version >= winVersion);
|
||||
}
|
||||
|
||||
public static bool IsAssociationOutdated(string currentIconPath, string currentAppPath)
|
||||
{
|
||||
var extReg = Registry.CurrentUser.OpenSubKey(ExtRegPath, false);
|
||||
var appReg = Registry.CurrentUser.OpenSubKey(AppAssocRegPath, false);
|
||||
var appAssocReg = Registry.CurrentUser.OpenSubKey(AppAssocRegPath, false);
|
||||
|
||||
if (extReg == null || appReg == null || appAssocReg == null) return true;
|
||||
if (extReg.OpenSubKey("DefaultIcon", false) == null) return true;
|
||||
if (extReg.OpenSubKey("PerceivedType", false) == null) return true;
|
||||
if (extReg.OpenSubKey("DefaultIcon", false)?.GetValue("").ToString() != currentIconPath) return true;
|
||||
if (appReg.OpenSubKey("shell\\open\\command", false) == null) return true;
|
||||
if (appReg.OpenSubKey("DefaultIcon", false) == null) return true;
|
||||
if (appReg.OpenSubKey("shell\\open\\command", false)?.GetValue("").ToString() != $"\"{currentAppPath}\" -i %i") return true;
|
||||
if (appReg.OpenSubKey("DefaultIcon", false)?.GetValue("").ToString() != currentIconPath) return true;
|
||||
if (appAssocReg.OpenSubKey("UserChoice", false) == null) return true;
|
||||
if (appAssocReg.OpenSubKey("UserChoice", false)?.GetValue("Progid").ToString() !=
|
||||
"Applications\\Wabbajack.exe") return true;
|
||||
|
||||
if (!IsWin8()) return false;
|
||||
|
||||
if (extReg.GetValue("").ToString() != Extension.Replace(".", "") + "_auto_file") return true;
|
||||
var win8FileReg = Registry.CurrentUser.OpenSubKey(Win8RegPath, false);
|
||||
if (win8FileReg?.OpenSubKey("shell\\open\\command", false) == null) return true;
|
||||
return win8FileReg.OpenSubKey("shell\\open\\command", false)?.GetValue("").ToString() !=
|
||||
$"\"{currentAppPath}\" -i %i";
|
||||
}
|
||||
|
||||
public static void AssociateExtension(string iconPath, string appPath)
|
||||
{
|
||||
var extReg = Registry.CurrentUser.CreateSubKey(ExtRegPath);
|
||||
if (Environment.OSVersion.Platform >= PlatformID.Win32NT && Environment.OSVersion.Version >= winVersion)
|
||||
if (IsWin8())
|
||||
extReg?.SetValue("", Extension.Replace(".", "") + "_auto_file");
|
||||
var appReg = Registry.CurrentUser.CreateSubKey(AppRegPath);
|
||||
var appAssocReg = Registry.CurrentUser.CreateSubKey(AppAssocRegPath);
|
||||
@ -40,10 +73,8 @@ namespace Wabbajack.Common
|
||||
appAssocReg?.CreateSubKey("UserChoice")?.SetValue("Progid", "Applications\\Wabbajack.exe");
|
||||
SHChangeNotify(0x000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
|
||||
|
||||
if (Environment.OSVersion.Platform < PlatformID.Win32NT ||
|
||||
Environment.OSVersion.Version < winVersion) return;
|
||||
var win8FileReg =
|
||||
Registry.CurrentUser.CreateSubKey($"Software\\Classes\\{Extension.Replace(".", "")}_auto_file");
|
||||
if (!IsWin8()) return;
|
||||
var win8FileReg = Registry.CurrentUser.CreateSubKey(Win8RegPath);
|
||||
win8FileReg?.CreateSubKey("shell\\open\\command")?.SetValue("", $"\"{appPath}\" -i %i");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user