mirror of
https://github.com/EpicMorg/windows2go-switcher.git
synced 2025-02-11 06:08:48 +03:00
code cleanup
This commit is contained in:
parent
703041b7a5
commit
60689cad5d
2
src/windows2go.switcher/FormMain.Designer.cs
generated
2
src/windows2go.switcher/FormMain.Designer.cs
generated
@ -101,7 +101,7 @@
|
|||||||
this.buttonSet.TabIndex = 1;
|
this.buttonSet.TabIndex = 1;
|
||||||
this.buttonSet.Text = "Set Some State";
|
this.buttonSet.Text = "Set Some State";
|
||||||
this.buttonSet.UseVisualStyleBackColor = true;
|
this.buttonSet.UseVisualStyleBackColor = true;
|
||||||
this.buttonSet.Click += new System.EventHandler(this.buttonSetNormal_Click);
|
this.buttonSet.Click += new System.EventHandler(this.buttonSet_Click);
|
||||||
//
|
//
|
||||||
// labelState
|
// labelState
|
||||||
//
|
//
|
||||||
|
@ -16,9 +16,7 @@ namespace windows2go.switcher {
|
|||||||
public FormMain() {
|
public FormMain() {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
UACSecurity.AddShieldToButton(buttonSet);
|
UACSecurity.AddShieldToButton(buttonSet);
|
||||||
|
|
||||||
if (UACSecurity.IsAdmin()) this.Text += " (Administrator)";
|
if (UACSecurity.IsAdmin()) this.Text += " (Administrator)";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FormMain_Load(object sender, EventArgs e) {
|
private void FormMain_Load(object sender, EventArgs e) {
|
||||||
@ -29,51 +27,37 @@ namespace windows2go.switcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void TryToGetValue() {
|
private void TryToGetValue() {
|
||||||
object PortableOperatingSystemValue = ControlKey.GetValue("PortableOperatingSystem");
|
object PortableOperatingSystemValue = ControlKey.GetValue("PortableOperatingSystem");
|
||||||
if(PortableOperatingSystemValue != null) {
|
if(PortableOperatingSystemValue != null) {
|
||||||
switch (ControlKey.GetValueKind("PortableOperatingSystem")) {
|
switch (ControlKey.GetValueKind("PortableOperatingSystem")) {
|
||||||
case RegistryValueKind.String:
|
case RegistryValueKind.String:
|
||||||
case RegistryValueKind.ExpandString:
|
case RegistryValueKind.ExpandString:
|
||||||
//MessageBox.Show("ValueST = " + PortableOperatingSystemValue);
|
|
||||||
inBadTypeState();
|
inBadTypeState();
|
||||||
break;
|
break;
|
||||||
case RegistryValueKind.Binary:
|
case RegistryValueKind.Binary:
|
||||||
/*
|
|
||||||
foreach (byte b in (byte[])PortableOperatingSystemValue) {
|
|
||||||
MessageBox.Show("{0:x2} " + b);
|
|
||||||
}
|
|
||||||
Console.WriteLine();
|
|
||||||
*/
|
|
||||||
inBadTypeState();
|
inBadTypeState();
|
||||||
break;
|
break;
|
||||||
case RegistryValueKind.DWord:
|
case RegistryValueKind.DWord:
|
||||||
//if "PortableOperatingSystem" and it;s value not normal. example = "PortableOperatingSystem=42"
|
//if "PortableOperatingSystem" and it;s value not normal. example = "PortableOperatingSystem=42"
|
||||||
if ((PortableOperatingSystemValue.ToString() != "0") && (PortableOperatingSystemValue.ToString() != "1")) {
|
if ((PortableOperatingSystemValue.ToString() != "0") && (PortableOperatingSystemValue.ToString() != "1")) {
|
||||||
//MessageBox.Show("ValueDW = " + Convert.ToString((Int32)PortableOperatingSystemValue));
|
|
||||||
inWrongValueState();
|
inWrongValueState();
|
||||||
} else if (PortableOperatingSystemValue.ToString() == "0") {
|
} else if (PortableOperatingSystemValue.ToString() == "0") {
|
||||||
inNormalValueState();
|
inNormalValueState();
|
||||||
//MessageBox.Show(PortableOperatingSystemValue.ToString(), "");
|
|
||||||
} else if(PortableOperatingSystemValue.ToString() == "1") {
|
} else if(PortableOperatingSystemValue.ToString() == "1") {
|
||||||
inPortableValueState();
|
inPortableValueState();
|
||||||
//MessageBox.Show(PortableOperatingSystemValue.ToString(), "");
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RegistryValueKind.QWord:
|
case RegistryValueKind.QWord:
|
||||||
//MessageBox.Show("ValueQW = " + Convert.ToString((Int64)PortableOperatingSystemValue));
|
|
||||||
inBadTypeState();
|
inBadTypeState();
|
||||||
break;
|
break;
|
||||||
case RegistryValueKind.MultiString:
|
case RegistryValueKind.MultiString:
|
||||||
foreach (string s in (string[])PortableOperatingSystemValue) {
|
foreach (string s in (string[])PortableOperatingSystemValue) {
|
||||||
//MessageBox.Show("[{0:s}], ", s);
|
|
||||||
inBadTypeState();
|
inBadTypeState();
|
||||||
}
|
}
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
//MessageBox.Show("Value = (Unknown)");
|
|
||||||
inBadTypeState();
|
inBadTypeState();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -81,19 +65,6 @@ namespace windows2go.switcher {
|
|||||||
} else {
|
} else {
|
||||||
inNotExistsState();
|
inNotExistsState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
try {
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
|
||||||
inUnexpectedlState();
|
|
||||||
MessageBox.Show(ex.ToString(), "");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region states
|
#region states
|
||||||
@ -154,7 +125,7 @@ namespace windows2go.switcher {
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region set states
|
||||||
private void SetNormalState() {
|
private void SetNormalState() {
|
||||||
ControlKey.SetValue("PortableOperatingSystem", 0, RegistryValueKind.DWord);
|
ControlKey.SetValue("PortableOperatingSystem", 0, RegistryValueKind.DWord);
|
||||||
}
|
}
|
||||||
@ -169,72 +140,9 @@ namespace windows2go.switcher {
|
|||||||
ControlKey.SetValue("PortableOperatingSystem", 1, RegistryValueKind.DWord);
|
ControlKey.SetValue("PortableOperatingSystem", 1, RegistryValueKind.DWord);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private void buttonSet_Click(object sender, EventArgs e) {
|
||||||
/*
|
|
||||||
private void FullRegistryCheck() {
|
|
||||||
GetState();
|
|
||||||
if (!KeyExists) {
|
|
||||||
inUnexpectedlState();
|
|
||||||
} else {
|
|
||||||
switch (PortableState) {
|
|
||||||
case true:
|
|
||||||
inPortableState();
|
|
||||||
break;
|
|
||||||
case false:
|
|
||||||
inNormalState();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
inUnexpectedlState();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void GetState() {
|
|
||||||
|
|
||||||
RegistryKey key = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32);
|
|
||||||
key = key.OpenSubKey(@"SYSTEM\CurrentControlSet\Control", true);
|
|
||||||
//check for exists "PortableOperatingSystem"
|
|
||||||
if (key != null) {
|
|
||||||
switch (key.GetValue("PortableOperatingSystem")) {
|
|
||||||
case 0:
|
|
||||||
PortableState = true;
|
|
||||||
KeyExists = true;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
PortableState = false;
|
|
||||||
KeyExists = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
PortableState = false;
|
|
||||||
KeyExists = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
private void inNormalState() {
|
|
||||||
buttonSetNormal.Enabled = false;
|
|
||||||
buttonSetPortable.Enabled = true;
|
|
||||||
labelState.Text = @"You are in normal mode";
|
|
||||||
labelState.ForeColor = Color.LimeGreen;
|
|
||||||
unExpected = false;
|
|
||||||
}
|
|
||||||
private void inPortableState() {
|
|
||||||
buttonSetNormal.Enabled = true;
|
|
||||||
buttonSetPortable.Enabled = false;
|
|
||||||
labelState.Text = @"You are in portable (Windows To Go) mode";
|
|
||||||
labelState.ForeColor = Color.Crimson;
|
|
||||||
unExpected = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
private void buttonSetNormal_Click(object sender, EventArgs e) {
|
|
||||||
// Registry.SetValue(keyName, "PortableOperatingSystem", 0);
|
|
||||||
// FullRegistryCheck();
|
|
||||||
switch (CurrentStateCode) {
|
switch (CurrentStateCode) {
|
||||||
//case when it not exists yet
|
//case when it not exists yet
|
||||||
case -1:
|
case -1:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user