initial commit
This commit is contained in:
commit
1b60743303
274 changed files with 25866 additions and 0 deletions
35
SEGATools/Registry/EditFlags.cs
Normal file
35
SEGATools/Registry/EditFlags.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Registry.EditFlags
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
using System;
|
||||
|
||||
namespace SEGATools.Registry
|
||||
{
|
||||
[Flags]
|
||||
public enum EditFlags : uint
|
||||
{
|
||||
None = 0,
|
||||
Exclude = 1,
|
||||
Show = 2,
|
||||
HasExtension = 4,
|
||||
NoEdit = 8,
|
||||
NoRemove = 16, // 0x00000010
|
||||
NoNewVerb = 32, // 0x00000020
|
||||
NoEditVerb = 64, // 0x00000040
|
||||
NoRemoveVerb = 128, // 0x00000080
|
||||
NoEditDesc = 256, // 0x00000100
|
||||
NoEditIcon = 512, // 0x00000200
|
||||
NoEditDflt = 1024, // 0x00000400
|
||||
NoEditVerbCmd = 2048, // 0x00000800
|
||||
NoEditVerbExe = 4096, // 0x00001000
|
||||
NoDDE = 8192, // 0x00002000
|
||||
NoEditMIME = 32768, // 0x00008000
|
||||
OpenIsSafe = 65536, // 0x00010000
|
||||
AlwaysUnsafe = 131072, // 0x00020000
|
||||
AlwaysShowExtension = 262144, // 0x00040000
|
||||
NoRecentDocuments = 1048576, // 0x00100000
|
||||
}
|
||||
}
|
249
SEGATools/Registry/FileAssociationInfo.cs
Normal file
249
SEGATools/Registry/FileAssociationInfo.cs
Normal file
|
@ -0,0 +1,249 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Registry.FileAssociationInfo
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace SEGATools.Registry
|
||||
{
|
||||
public class FileAssociationInfo
|
||||
{
|
||||
private RegistryWrapper registryWrapper = new RegistryWrapper();
|
||||
private string extension;
|
||||
|
||||
public static string[] GetExtensions()
|
||||
{
|
||||
RegistryKey classesRoot = Microsoft.Win32.Registry.ClassesRoot;
|
||||
List<string> stringList = new List<string>();
|
||||
foreach (string subKeyName in classesRoot.GetSubKeyNames())
|
||||
{
|
||||
if (subKeyName.StartsWith("."))
|
||||
stringList.Add(subKeyName);
|
||||
}
|
||||
return stringList.ToArray();
|
||||
}
|
||||
|
||||
public string ContentType
|
||||
{
|
||||
get => this.GetContentType(this);
|
||||
set => this.SetContentType(this, value);
|
||||
}
|
||||
|
||||
public bool Exists
|
||||
{
|
||||
get
|
||||
{
|
||||
RegistryKey classesRoot = Microsoft.Win32.Registry.ClassesRoot;
|
||||
try
|
||||
{
|
||||
if (classesRoot.OpenSubKey(this.extension) == null)
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public string Extension
|
||||
{
|
||||
get => this.extension;
|
||||
set => this.extension = value;
|
||||
}
|
||||
|
||||
public string[] OpenWithList
|
||||
{
|
||||
get => this.GetOpenWithList(this);
|
||||
set => this.SetOpenWithList(this, value);
|
||||
}
|
||||
|
||||
public PerceivedTypes PerceivedType
|
||||
{
|
||||
get => this.GetPerceivedType(this);
|
||||
set => this.SetPerceivedType(this, value);
|
||||
}
|
||||
|
||||
public Guid PersistentHandler
|
||||
{
|
||||
get => this.GetPersistentHandler(this);
|
||||
set => this.SetPersistentHandler(this, value);
|
||||
}
|
||||
|
||||
[XmlAttribute]
|
||||
public string ProgID
|
||||
{
|
||||
get => this.GetProgID(this);
|
||||
set => this.SetProgID(this, value);
|
||||
}
|
||||
|
||||
public void Create() => this.Create(this);
|
||||
|
||||
public void Delete() => this.Delete(this);
|
||||
|
||||
public bool IsValid(string extension, string progId)
|
||||
{
|
||||
FileAssociationInfo fileAssociationInfo = new FileAssociationInfo(extension);
|
||||
return fileAssociationInfo.Exists && !(progId != fileAssociationInfo.ProgID);
|
||||
}
|
||||
|
||||
public FileAssociationInfo(string extension) => this.extension = extension;
|
||||
|
||||
public FileAssociationInfo Create(string progId) => this.Create(progId, PerceivedTypes.None, string.Empty, (string[]) null);
|
||||
|
||||
public FileAssociationInfo Create(
|
||||
string progId,
|
||||
PerceivedTypes perceivedType)
|
||||
{
|
||||
return this.Create(progId, perceivedType, string.Empty, (string[]) null);
|
||||
}
|
||||
|
||||
public FileAssociationInfo Create(
|
||||
string progId,
|
||||
PerceivedTypes perceivedType,
|
||||
string contentType)
|
||||
{
|
||||
return this.Create(progId, PerceivedTypes.None, contentType, (string[]) null);
|
||||
}
|
||||
|
||||
public FileAssociationInfo Create(
|
||||
string progId,
|
||||
PerceivedTypes perceivedType,
|
||||
string contentType,
|
||||
string[] openwithList)
|
||||
{
|
||||
FileAssociationInfo fileAssociationInfo = new FileAssociationInfo(this.extension);
|
||||
if (fileAssociationInfo.Exists)
|
||||
fileAssociationInfo.Delete();
|
||||
fileAssociationInfo.Create();
|
||||
fileAssociationInfo.ProgID = progId;
|
||||
if (perceivedType != PerceivedTypes.None)
|
||||
fileAssociationInfo.PerceivedType = perceivedType;
|
||||
if (contentType != string.Empty)
|
||||
fileAssociationInfo.ContentType = contentType;
|
||||
if (openwithList != null)
|
||||
fileAssociationInfo.OpenWithList = openwithList;
|
||||
return fileAssociationInfo;
|
||||
}
|
||||
|
||||
protected string[] GetOpenWithList(FileAssociationInfo file)
|
||||
{
|
||||
if (!file.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
RegistryKey registryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(file.extension).OpenSubKey("OpenWithList");
|
||||
return registryKey == null ? new string[0] : registryKey.GetSubKeyNames();
|
||||
}
|
||||
|
||||
protected void SetOpenWithList(FileAssociationInfo file, string[] programList)
|
||||
{
|
||||
if (!file.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
RegistryKey registryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(file.extension, true);
|
||||
if (registryKey.OpenSubKey("OpenWithList", true) != null)
|
||||
registryKey.DeleteSubKeyTree("OpenWithList");
|
||||
RegistryKey subKey = registryKey.CreateSubKey("OpenWithList");
|
||||
foreach (string program in programList)
|
||||
subKey.CreateSubKey(program);
|
||||
ShellNotification.NotifyOfChange();
|
||||
}
|
||||
|
||||
protected PerceivedTypes GetPerceivedType(FileAssociationInfo file)
|
||||
{
|
||||
if (!file.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
object obj = this.registryWrapper.Read(file.extension, "PerceivedType");
|
||||
PerceivedTypes perceivedTypes = PerceivedTypes.None;
|
||||
if (obj == null)
|
||||
return perceivedTypes;
|
||||
try
|
||||
{
|
||||
perceivedTypes = (PerceivedTypes) Enum.Parse(typeof (PerceivedTypes), obj.ToString(), true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
return perceivedTypes;
|
||||
}
|
||||
|
||||
protected void SetPerceivedType(FileAssociationInfo file, PerceivedTypes type)
|
||||
{
|
||||
if (!file.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
this.registryWrapper.Write(file.extension, "PerceivedType", (object) type.ToString());
|
||||
ShellNotification.NotifyOfChange();
|
||||
}
|
||||
|
||||
protected Guid GetPersistentHandler(FileAssociationInfo file)
|
||||
{
|
||||
if (!file.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
object obj = this.registryWrapper.Read(file.extension + "\\PersistentHandler", string.Empty);
|
||||
return obj == null ? new Guid() : new Guid(obj.ToString());
|
||||
}
|
||||
|
||||
protected void SetPersistentHandler(FileAssociationInfo file, Guid persistentHandler)
|
||||
{
|
||||
if (!file.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
if (persistentHandler == Guid.Empty)
|
||||
return;
|
||||
this.registryWrapper.Write(file.extension + "\\" + (object) this.PersistentHandler, string.Empty, (object) persistentHandler);
|
||||
ShellNotification.NotifyOfChange();
|
||||
}
|
||||
|
||||
protected string GetContentType(FileAssociationInfo file)
|
||||
{
|
||||
if (!file.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
object obj = this.registryWrapper.Read(file.extension, "Content Type");
|
||||
return obj == null ? string.Empty : obj.ToString();
|
||||
}
|
||||
|
||||
protected void SetContentType(FileAssociationInfo file, string type)
|
||||
{
|
||||
if (!file.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
this.registryWrapper.Write(file.extension, "Content Type", (object) type);
|
||||
ShellNotification.NotifyOfChange();
|
||||
}
|
||||
|
||||
protected string GetProgID(FileAssociationInfo file)
|
||||
{
|
||||
if (!file.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
object obj = this.registryWrapper.Read(file.extension, string.Empty);
|
||||
return obj == null ? string.Empty : obj.ToString();
|
||||
}
|
||||
|
||||
protected void SetProgID(FileAssociationInfo file, string progId)
|
||||
{
|
||||
if (!file.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
this.registryWrapper.Write(file.extension, string.Empty, (object) progId);
|
||||
ShellNotification.NotifyOfChange();
|
||||
}
|
||||
|
||||
protected void Create(FileAssociationInfo file)
|
||||
{
|
||||
if (file.Exists)
|
||||
file.Delete();
|
||||
Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(file.extension);
|
||||
}
|
||||
|
||||
protected void Delete(FileAssociationInfo file)
|
||||
{
|
||||
if (!file.Exists)
|
||||
throw new Exception("Key not found.");
|
||||
Microsoft.Win32.Registry.ClassesRoot.DeleteSubKeyTree(file.extension);
|
||||
ShellNotification.NotifyOfChange();
|
||||
}
|
||||
}
|
||||
}
|
19
SEGATools/Registry/PerceivedTypes.cs
Normal file
19
SEGATools/Registry/PerceivedTypes.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Registry.PerceivedTypes
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
namespace SEGATools.Registry
|
||||
{
|
||||
public enum PerceivedTypes
|
||||
{
|
||||
None,
|
||||
Image,
|
||||
Text,
|
||||
Audio,
|
||||
Video,
|
||||
Compressed,
|
||||
System,
|
||||
}
|
||||
}
|
328
SEGATools/Registry/ProgramAssociationInfo.cs
Normal file
328
SEGATools/Registry/ProgramAssociationInfo.cs
Normal file
|
@ -0,0 +1,328 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Registry.ProgramAssociationInfo
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SEGATools.Registry
|
||||
{
|
||||
public class ProgramAssociationInfo
|
||||
{
|
||||
private RegistryWrapper registryWrapper = new RegistryWrapper();
|
||||
protected string progId;
|
||||
|
||||
public bool AlwaysShowExtension
|
||||
{
|
||||
get => this.GetAlwaysShowExt();
|
||||
set => this.SetAlwaysShowExt(value);
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get => this.GetDescription();
|
||||
set => this.SetDescription(value);
|
||||
}
|
||||
|
||||
public EditFlags EditFlags
|
||||
{
|
||||
get => this.GetEditFlags();
|
||||
set => this.SetEditFlags(value);
|
||||
}
|
||||
|
||||
public ProgramIcon DefaultIcon
|
||||
{
|
||||
get => this.GetDefaultIcon();
|
||||
set => this.SetDefaultIcon(value);
|
||||
}
|
||||
|
||||
public ProgramVerb[] Verbs
|
||||
{
|
||||
get => this.GetVerbs();
|
||||
set => this.SetVerbs(value);
|
||||
}
|
||||
|
||||
public string ProgID => this.progId;
|
||||
|
||||
public bool Exists
|
||||
{
|
||||
get
|
||||
{
|
||||
RegistryKey classesRoot = Microsoft.Win32.Registry.ClassesRoot;
|
||||
try
|
||||
{
|
||||
if (this.progId == string.Empty)
|
||||
return false;
|
||||
if (classesRoot.OpenSubKey(this.progId) == null)
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Create()
|
||||
{
|
||||
if (this.Exists)
|
||||
return;
|
||||
Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(this.progId);
|
||||
}
|
||||
|
||||
public ProgramAssociationInfo Create(ProgramVerb verb) => this.Create(string.Empty, EditFlags.None, new ProgramVerb[1]
|
||||
{
|
||||
verb
|
||||
});
|
||||
|
||||
public ProgramAssociationInfo Create(ProgramVerb[] verbs) => this.Create(string.Empty, EditFlags.None, verbs);
|
||||
|
||||
public ProgramAssociationInfo Create(string description, ProgramVerb verb) => this.Create(description, EditFlags.None, new ProgramVerb[1]
|
||||
{
|
||||
verb
|
||||
});
|
||||
|
||||
public ProgramAssociationInfo Create(
|
||||
string description,
|
||||
ProgramVerb[] verbs)
|
||||
{
|
||||
return this.Create(description, EditFlags.None, verbs);
|
||||
}
|
||||
|
||||
public ProgramAssociationInfo Create(
|
||||
string description,
|
||||
EditFlags editFlags,
|
||||
ProgramVerb verb)
|
||||
{
|
||||
return this.Create(description, editFlags, new ProgramVerb[1]
|
||||
{
|
||||
verb
|
||||
});
|
||||
}
|
||||
|
||||
public ProgramAssociationInfo Create(
|
||||
string description,
|
||||
EditFlags editFlags,
|
||||
ProgramVerb[] verbs)
|
||||
{
|
||||
if (this.Exists)
|
||||
this.Delete();
|
||||
this.Create();
|
||||
if (description != string.Empty)
|
||||
this.Description = description;
|
||||
if (editFlags != EditFlags.None)
|
||||
this.EditFlags = editFlags;
|
||||
this.Verbs = verbs;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected bool GetAlwaysShowExt()
|
||||
{
|
||||
if (!this.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
return !(Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(this.progId).GetValue("AlwaysShowExt", (object) "ThisValueShouldNotExist").ToString() == "ThisValueShouldNotExist");
|
||||
}
|
||||
|
||||
protected void SetAlwaysShowExt(bool value)
|
||||
{
|
||||
if (!this.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
if (value)
|
||||
this.registryWrapper.Write(this.progId, "AlwaysShowExt", (object) string.Empty);
|
||||
else
|
||||
this.registryWrapper.Delete(this.progId, "AlwaysShowExt");
|
||||
ShellNotification.NotifyOfChange();
|
||||
}
|
||||
|
||||
protected string GetDescription()
|
||||
{
|
||||
if (!this.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
object obj = this.registryWrapper.Read(this.progId, string.Empty);
|
||||
return obj == null ? string.Empty : obj.ToString();
|
||||
}
|
||||
|
||||
protected void SetDescription(string description)
|
||||
{
|
||||
if (!this.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
this.registryWrapper.Write(this.progId, string.Empty, (object) description);
|
||||
ShellNotification.NotifyOfChange();
|
||||
}
|
||||
|
||||
protected EditFlags GetEditFlags()
|
||||
{
|
||||
if (!this.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
object obj = this.registryWrapper.Read(this.progId, "EditFlags");
|
||||
if (obj == null)
|
||||
return EditFlags.None;
|
||||
if (obj is byte[])
|
||||
{
|
||||
int val;
|
||||
if (!this.TryGetInt(obj as byte[], out val))
|
||||
return EditFlags.None;
|
||||
obj = (object) val;
|
||||
}
|
||||
try
|
||||
{
|
||||
return (EditFlags) Convert.ToUInt32(obj);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
return EditFlags.None;
|
||||
}
|
||||
|
||||
protected void SetEditFlags(EditFlags flags)
|
||||
{
|
||||
if (!this.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
this.registryWrapper.Write(this.progId, "EditFlags", (object) flags);
|
||||
ShellNotification.NotifyOfChange();
|
||||
}
|
||||
|
||||
protected ProgramIcon GetDefaultIcon()
|
||||
{
|
||||
if (!this.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
object obj = this.registryWrapper.Read(this.progId + "\\DefaultIcon", "");
|
||||
return obj == null ? ProgramIcon.None : ProgramIcon.Parse(obj.ToString());
|
||||
}
|
||||
|
||||
protected void SetDefaultIcon(ProgramIcon icon)
|
||||
{
|
||||
if (!this.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
if (!(icon != ProgramIcon.None))
|
||||
return;
|
||||
this.registryWrapper.Write(this.progId + "\\DefaultIcon", "", (object) icon.ToString());
|
||||
ShellNotification.NotifyOfChange();
|
||||
}
|
||||
|
||||
protected ProgramVerb[] GetVerbs()
|
||||
{
|
||||
if (!this.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
RegistryKey classesRoot = Microsoft.Win32.Registry.ClassesRoot;
|
||||
RegistryKey registryKey1 = classesRoot.OpenSubKey(this.progId);
|
||||
List<ProgramVerb> programVerbList = new List<ProgramVerb>();
|
||||
RegistryKey registryKey2 = registryKey1.OpenSubKey("shell", false);
|
||||
if (registryKey2 != null)
|
||||
{
|
||||
foreach (string subKeyName in registryKey2.GetSubKeyNames())
|
||||
{
|
||||
RegistryKey registryKey3 = registryKey2.OpenSubKey(subKeyName);
|
||||
if (registryKey3 != null)
|
||||
{
|
||||
RegistryKey registryKey4 = registryKey3.OpenSubKey("command");
|
||||
if (registryKey4 != null)
|
||||
{
|
||||
string command = (string) registryKey4.GetValue("", (object) "", RegistryValueOptions.DoNotExpandEnvironmentNames);
|
||||
programVerbList.Add(new ProgramVerb(subKeyName, command));
|
||||
}
|
||||
}
|
||||
}
|
||||
registryKey2.Close();
|
||||
}
|
||||
classesRoot.Close();
|
||||
return programVerbList.ToArray();
|
||||
}
|
||||
|
||||
protected void SetVerbs(ProgramVerb[] verbs)
|
||||
{
|
||||
if (!this.Exists)
|
||||
throw new Exception("Extension does not exist");
|
||||
RegistryKey registryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(this.progId, true);
|
||||
if (registryKey.OpenSubKey("shell", true) != null)
|
||||
registryKey.DeleteSubKeyTree("shell");
|
||||
RegistryKey subKey1 = registryKey.CreateSubKey("shell");
|
||||
foreach (ProgramVerb verb in verbs)
|
||||
{
|
||||
RegistryKey subKey2 = subKey1.CreateSubKey(verb.Name.ToLower());
|
||||
RegistryKey subKey3 = subKey2.CreateSubKey("command");
|
||||
subKey3.SetValue(string.Empty, (object) verb.Command, RegistryValueKind.ExpandString);
|
||||
subKey3.Close();
|
||||
subKey2.Close();
|
||||
}
|
||||
ShellNotification.NotifyOfChange();
|
||||
}
|
||||
|
||||
protected void AddVerbInternal(ProgramVerb verb)
|
||||
{
|
||||
RegistryKey classesRoot = Microsoft.Win32.Registry.ClassesRoot;
|
||||
RegistryKey registryKey1 = classesRoot.OpenSubKey(this.progId).OpenSubKey("shell", true) ?? classesRoot.OpenSubKey(this.progId, true).CreateSubKey("shell");
|
||||
RegistryKey registryKey2 = registryKey1.OpenSubKey(verb.Name, true) ?? registryKey1.CreateSubKey(verb.Name);
|
||||
RegistryKey registryKey3 = registryKey2.OpenSubKey("command", true) ?? registryKey2.CreateSubKey("command");
|
||||
registryKey3.SetValue(string.Empty, (object) verb.Command, RegistryValueKind.ExpandString);
|
||||
registryKey3.Close();
|
||||
registryKey2.Close();
|
||||
classesRoot.Close();
|
||||
ShellNotification.NotifyOfChange();
|
||||
}
|
||||
|
||||
protected void RemoveVerbInternal(string name)
|
||||
{
|
||||
RegistryKey classesRoot = Microsoft.Win32.Registry.ClassesRoot;
|
||||
RegistryKey registryKey = classesRoot.OpenSubKey(this.progId).OpenSubKey("shell", true);
|
||||
if (registryKey == null)
|
||||
throw new RegistryException("Shell key not found");
|
||||
foreach (string subKeyName in registryKey.GetSubKeyNames())
|
||||
{
|
||||
if (subKeyName == name)
|
||||
{
|
||||
registryKey.DeleteSubKeyTree(name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
registryKey.Close();
|
||||
classesRoot.Close();
|
||||
ShellNotification.NotifyOfChange();
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
if (!this.Exists)
|
||||
throw new Exception("Key not found.");
|
||||
Microsoft.Win32.Registry.ClassesRoot.DeleteSubKeyTree(this.progId);
|
||||
}
|
||||
|
||||
public void AddVerb(ProgramVerb verb) => this.AddVerbInternal(verb);
|
||||
|
||||
public void RemoveVerb(ProgramVerb verb)
|
||||
{
|
||||
if (verb == null)
|
||||
throw new NullReferenceException();
|
||||
this.RemoveVerb(verb.Name);
|
||||
}
|
||||
|
||||
public void RemoveVerb(string name) => this.RemoveVerbInternal(name);
|
||||
|
||||
public ProgramAssociationInfo(string progId) => this.progId = progId;
|
||||
|
||||
private bool TryGetInt(byte[] arr, out int val)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (arr.Length == 0)
|
||||
{
|
||||
val = -1;
|
||||
return false;
|
||||
}
|
||||
val = arr.Length != 1 ? BitConverter.ToInt32(arr, 0) : (int) arr[0];
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
val = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
70
SEGATools/Registry/ProgramIcon.cs
Normal file
70
SEGATools/Registry/ProgramIcon.cs
Normal file
|
@ -0,0 +1,70 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Registry.ProgramIcon
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
namespace SEGATools.Registry
|
||||
{
|
||||
public class ProgramIcon
|
||||
{
|
||||
public static readonly ProgramIcon None = new ProgramIcon();
|
||||
private string path;
|
||||
private int index;
|
||||
|
||||
public int Index
|
||||
{
|
||||
get => this.index;
|
||||
set => this.index = value;
|
||||
}
|
||||
|
||||
public string Path
|
||||
{
|
||||
get => this.path;
|
||||
set => this.path = value;
|
||||
}
|
||||
|
||||
public ProgramIcon(string path, int index)
|
||||
{
|
||||
this.path = path;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public ProgramIcon(string path)
|
||||
{
|
||||
this.path = path;
|
||||
this.index = 0;
|
||||
}
|
||||
|
||||
public ProgramIcon()
|
||||
{
|
||||
this.path = string.Empty;
|
||||
this.index = 0;
|
||||
}
|
||||
|
||||
public override string ToString() => this.path + "," + this.index.ToString();
|
||||
|
||||
public static ProgramIcon Parse(string regString)
|
||||
{
|
||||
if (regString == string.Empty)
|
||||
return new ProgramIcon("");
|
||||
if (regString.StartsWith("\"") && regString.EndsWith("\"") && regString.Length > 3)
|
||||
regString = regString.Substring(1, regString.Length - 2);
|
||||
int index = 0;
|
||||
int length = regString.IndexOf(",");
|
||||
if (length == -1)
|
||||
length = regString.Length;
|
||||
else
|
||||
index = int.Parse(regString.Substring(length + 1));
|
||||
return new ProgramIcon(regString.Substring(0, length), index);
|
||||
}
|
||||
|
||||
public static bool operator ==(ProgramIcon lv, ProgramIcon rv) => object.ReferenceEquals((object) lv, (object) null) && object.ReferenceEquals((object) rv, (object) null) || !object.ReferenceEquals((object) lv, (object) null) && !object.ReferenceEquals((object) rv, (object) null) && (lv.path == rv.path && lv.index == rv.index);
|
||||
|
||||
public static bool operator !=(ProgramIcon lv, ProgramIcon rv) => !(lv == rv);
|
||||
|
||||
public override bool Equals(object obj) => this == obj as ProgramIcon;
|
||||
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
}
|
||||
}
|
24
SEGATools/Registry/ProgramVerb.cs
Normal file
24
SEGATools/Registry/ProgramVerb.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Registry.ProgramVerb
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
namespace SEGATools.Registry
|
||||
{
|
||||
public class ProgramVerb
|
||||
{
|
||||
private string command;
|
||||
private string name;
|
||||
|
||||
public string Command => this.command;
|
||||
|
||||
public string Name => this.name;
|
||||
|
||||
public ProgramVerb(string name, string command)
|
||||
{
|
||||
this.name = name;
|
||||
this.command = command;
|
||||
}
|
||||
}
|
||||
}
|
27
SEGATools/Registry/RegistryException.cs
Normal file
27
SEGATools/Registry/RegistryException.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Registry.RegistryException
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
using System;
|
||||
|
||||
namespace SEGATools.Registry
|
||||
{
|
||||
public class RegistryException : ApplicationException
|
||||
{
|
||||
public RegistryException()
|
||||
{
|
||||
}
|
||||
|
||||
public RegistryException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public RegistryException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
103
SEGATools/Registry/RegistryWrapper.cs
Normal file
103
SEGATools/Registry/RegistryWrapper.cs
Normal file
|
@ -0,0 +1,103 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Registry.RegistryWrapper
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
|
||||
namespace SEGATools.Registry
|
||||
{
|
||||
internal class RegistryWrapper
|
||||
{
|
||||
public object Read(string path, string valueName)
|
||||
{
|
||||
RegistryKey registryKey = Microsoft.Win32.Registry.ClassesRoot;
|
||||
string[] strArray = path.Split('\\');
|
||||
if (strArray == null || strArray.Length == 0)
|
||||
return (object) null;
|
||||
for (int index = 0; index < strArray.Length; ++index)
|
||||
{
|
||||
registryKey = registryKey.OpenSubKey(strArray[index]);
|
||||
if (registryKey == null)
|
||||
return (object) null;
|
||||
if (index == strArray.Length - 1)
|
||||
return registryKey.GetValue(valueName, (object) null, RegistryValueOptions.DoNotExpandEnvironmentNames);
|
||||
}
|
||||
return (object) null;
|
||||
}
|
||||
|
||||
public void Write(string path, string valueName, object value)
|
||||
{
|
||||
RegistryKey registryKey1 = Microsoft.Win32.Registry.ClassesRoot;
|
||||
RegistryKey registryKey2 = registryKey1;
|
||||
string[] strArray = path.Split('\\');
|
||||
if (strArray == null || strArray.Length == 0)
|
||||
return;
|
||||
for (int index = 0; index < strArray.Length; ++index)
|
||||
{
|
||||
registryKey1 = registryKey1.OpenSubKey(strArray[index], true) ?? registryKey2.CreateSubKey(strArray[index]);
|
||||
if (index == strArray.Length - 1)
|
||||
{
|
||||
if (value is string)
|
||||
registryKey1.SetValue(valueName, (object) value.ToString());
|
||||
else if (value is uint || value.GetType().IsEnum)
|
||||
{
|
||||
if (registryKey1.GetValue(valueName, (object) null) == null)
|
||||
{
|
||||
registryKey1.SetValue(valueName, value, RegistryValueKind.DWord);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (registryKey1.GetValueKind(valueName))
|
||||
{
|
||||
case RegistryValueKind.String:
|
||||
registryKey1.SetValue(valueName, (object) ("x" + ((uint) value).ToString("X8")));
|
||||
break;
|
||||
case RegistryValueKind.Binary:
|
||||
uint num = (uint) value;
|
||||
byte[] numArray = new byte[4]
|
||||
{
|
||||
(byte) (num & (uint) byte.MaxValue),
|
||||
(byte) ((num & 65280U) >> 1),
|
||||
(byte) ((num & 16711680U) >> 2),
|
||||
(byte) ((num & 4278190080U) >> 3)
|
||||
};
|
||||
numArray[0] = (byte) (num & (uint) byte.MaxValue);
|
||||
numArray[1] = (byte) ((num & 65280U) >> 8);
|
||||
numArray[2] = (byte) ((num & 16711680U) >> 16);
|
||||
numArray[3] = (byte) ((num & 4278190080U) >> 24);
|
||||
registryKey1.SetValue(valueName, (object) numArray, RegistryValueKind.Binary);
|
||||
break;
|
||||
case RegistryValueKind.DWord:
|
||||
registryKey1.SetValue(valueName, value, RegistryValueKind.DWord);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (value is Guid guid)
|
||||
registryKey1.SetValue(valueName, (object) guid.ToString("B"));
|
||||
}
|
||||
registryKey2 = registryKey1;
|
||||
}
|
||||
registryKey1?.Close();
|
||||
}
|
||||
|
||||
public void Delete(string path, string valueName)
|
||||
{
|
||||
RegistryKey registryKey = Microsoft.Win32.Registry.ClassesRoot;
|
||||
string[] strArray = path.Split('\\');
|
||||
if (strArray == null || strArray.Length == 0)
|
||||
return;
|
||||
for (int index = 0; index < strArray.Length; ++index)
|
||||
{
|
||||
registryKey = registryKey.OpenSubKey(strArray[index], true);
|
||||
if (registryKey == null)
|
||||
break;
|
||||
if (index == strArray.Length - 1)
|
||||
registryKey.DeleteValue(valueName, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
66
SEGATools/Registry/ShellNotification.cs
Normal file
66
SEGATools/Registry/ShellNotification.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: SEGATools.Registry.ShellNotification
|
||||
// Assembly: SEGATools, Version=1.0.3.0, Culture=neutral, PublicKeyToken=611be24fdeb07e08
|
||||
// MVID: D631183F-57B1-40A1-B502-5364D288307A
|
||||
// Assembly location: SEGATools.dll
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SEGATools.Registry
|
||||
{
|
||||
internal class ShellNotification
|
||||
{
|
||||
[DllImport("shell32.dll")]
|
||||
private static extern void SHChangeNotify(
|
||||
uint wEventId,
|
||||
uint uFlags,
|
||||
IntPtr dwItem1,
|
||||
IntPtr dwItem2);
|
||||
|
||||
public static void NotifyOfChange() => ShellNotification.SHChangeNotify(134217728U, 8192U, IntPtr.Zero, IntPtr.Zero);
|
||||
|
||||
[Flags]
|
||||
private enum ShellChangeNotificationEvents : uint
|
||||
{
|
||||
SHCNE_RENAMEITEM = 1,
|
||||
SHCNE_CREATE = 2,
|
||||
SHCNE_DELETE = 4,
|
||||
SHCNE_MKDIR = 8,
|
||||
SHCNE_RMDIR = 16, // 0x00000010
|
||||
SHCNE_MEDIAINSERTED = 32, // 0x00000020
|
||||
SHCNE_MEDIAREMOVED = 64, // 0x00000040
|
||||
SHCNE_DRIVEREMOVED = 128, // 0x00000080
|
||||
SHCNE_DRIVEADD = 256, // 0x00000100
|
||||
SHCNE_NETSHARE = 512, // 0x00000200
|
||||
SHCNE_NETUNSHARE = 1024, // 0x00000400
|
||||
SHCNE_ATTRIBUTES = 2048, // 0x00000800
|
||||
SHCNE_UPDATEDIR = 4096, // 0x00001000
|
||||
SHCNE_UPDATEITEM = 8192, // 0x00002000
|
||||
SHCNE_SERVERDISCONNECT = 16384, // 0x00004000
|
||||
SHCNE_UPDATEIMAGE = 32768, // 0x00008000
|
||||
SHCNE_DRIVEADDGUI = 65536, // 0x00010000
|
||||
SHCNE_RENAMEFOLDER = 131072, // 0x00020000
|
||||
SHCNE_FREESPACE = 262144, // 0x00040000
|
||||
SHCNE_EXTENDED_EVENT = 67108864, // 0x04000000
|
||||
SHCNE_ASSOCCHANGED = 134217728, // 0x08000000
|
||||
SHCNE_DISKEVENTS = SHCNE_RENAMEFOLDER | SHCNE_UPDATEITEM | SHCNE_UPDATEDIR | SHCNE_ATTRIBUTES | SHCNE_RMDIR | SHCNE_MKDIR | SHCNE_DELETE | SHCNE_CREATE | SHCNE_RENAMEITEM, // 0x0002381F
|
||||
SHCNE_GLOBALEVENTS = SHCNE_ASSOCCHANGED | SHCNE_EXTENDED_EVENT | SHCNE_FREESPACE | SHCNE_DRIVEADDGUI | SHCNE_UPDATEIMAGE | SHCNE_DRIVEADD | SHCNE_DRIVEREMOVED | SHCNE_MEDIAREMOVED | SHCNE_MEDIAINSERTED, // 0x0C0581E0
|
||||
SHCNE_ALLEVENTS = 2147483647, // 0x7FFFFFFF
|
||||
SHCNE_INTERRUPT = 2147483648, // 0x80000000
|
||||
}
|
||||
|
||||
private enum ShellChangeNotificationFlags
|
||||
{
|
||||
SHCNF_IDLIST = 0,
|
||||
SHCNF_PATHA = 1,
|
||||
SHCNF_PRINTERA = 2,
|
||||
SHCNF_DWORD = 3,
|
||||
SHCNF_PATHW = 5,
|
||||
SHCNF_PRINTERW = 6,
|
||||
SHCNF_TYPE = 255, // 0x000000FF
|
||||
SHCNF_FLUSH = 4096, // 0x00001000
|
||||
SHCNF_FLUSHNOWAIT = 8192, // 0x00002000
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue