66using System . Linq ;
77using System . Text ;
88using System . Windows . Forms ;
9+ using System . Runtime . InteropServices ;
910
1011using System . Diagnostics ;
1112using Microsoft . Win32 ;
@@ -60,82 +61,36 @@ public App()
6061
6162 public void UpdatePolicyState ( )
6263 {
63- var productPolicyEditor = new ProductPolicyEditor ( ) ;
64+ var productPolicyEditor = new ProductPolicyReader ( ) ;
6465
6566 var policyState = productPolicyEditor . GetPolicyStateByName ( "WSLicensingService-LOBSideloadingActivated" ) ;
6667 var isSideloadingKeyInstalled = LOBManager . IsSideloadingKeyInstalled ( ) ;
6768
69+ statusLabel . ForeColor = isSideloadingKeyInstalled ? Color . DarkGreen : Color . DarkOrange ;
70+ disableButton . Enabled = isSideloadingKeyInstalled ;
71+
6872 switch ( policyState )
6973 {
7074 case PolicyState . Disabled :
71- statusLabel . Text = "Disabled" ;
72- statusLabel . ForeColor = Color . DarkRed ;
73- break ;
74- case PolicyState . Enabled :
7575 if ( isSideloadingKeyInstalled )
76- {
77- statusLabel . Text = "Sideloading enabled" ;
78- statusLabel . ForeColor = Color . DarkGreen ;
79- }
76+ statusLabel . Text = "Enabling..." ;
8077 else
8178 {
82- statusLabel . Text = "Sideloading will be disabled soon " ;
83- statusLabel . ForeColor = Color . DarkOrange ;
79+ statusLabel . Text = "Disabled " ;
80+ statusLabel . ForeColor = Color . DarkRed ;
8481 }
8582 break ;
86- case PolicyState . Unknown :
83+ case PolicyState . Enabled :
84+ statusLabel . Text = isSideloadingKeyInstalled ? "Sideloading enabled" : "Disabling..." ;
85+ break ;
86+ default :
8787 statusLabel . Text = "Unknown" ;
8888 statusLabel . ForeColor = Color . Black ;
8989 break ;
9090 }
9191 }
9292
93- private string CombineArguments ( params string [ ] arguments )
94- {
95- return string . Join ( " " , arguments ) ;
96- }
97-
98- private void SetSetupParameter ( string key , object value , RegistryValueKind valueKind )
99- {
100- Registry . SetValue ( "HKEY_LOCAL_MACHINE\\ SYSTEM\\ Setup" , key , value , valueKind ) ;
101- }
102-
103- private void SetSetupType ( int type )
104- {
105- SetSetupParameter ( "SetupType" , type , RegistryValueKind . DWord ) ;
106- }
107-
108- private void button1_Click ( object sender , EventArgs e )
109- {
110- StartupArgument startupArgument ;
111-
112- if ( LOBCheckBox . Checked && SPPCheckBox . Checked )
113- startupArgument = StartupArgument . EnableLOBAndEnableSPP ;
114- else if ( LOBCheckBox . Checked )
115- startupArgument = StartupArgument . EnableLOBAndDisableSPP ;
116- else if ( SPPCheckBox . Checked )
117- startupArgument = StartupArgument . DisableLOBAndEnableSPP ;
118- else
119- startupArgument = StartupArgument . DisableLOBAndDisableSPP ;
120-
121- string commandLine = CombineArguments ( new string [ ] { Application . ExecutablePath , StartupArguments . GetStartupArgumentString ( startupArgument ) } ) ;
122-
123- SetSetupParameter ( "CmdLine" , commandLine , RegistryValueKind . String ) ;
124- SetSetupType ( 1 ) ;
125- DialogResult result = MessageBox . Show ( "Sideloading will be enabled after a reboot. Would you like to reboot now?" , "Reboot?" , MessageBoxButtons . YesNoCancel , MessageBoxIcon . Question ) ;
126-
127- switch ( result )
128- {
129- case DialogResult . Yes :
130- Rebooter . Reboot ( ) ;
131- break ;
132- case DialogResult . Cancel :
133- SetSetupType ( 0 ) ;
134- break ;
135- }
136- }
137-
138- private void JailbreakButton_Click ( object sender , EventArgs e )
93+ private void Jailbreak ( object sender , EventArgs e )
13994 {
14095 try
14196 {
@@ -145,12 +100,19 @@ private void JailbreakButton_Click(object sender, EventArgs e)
145100 return ;
146101
147102 LOBManager . ActivateZeroCID ( ) ;
103+
104+ LOBEnabled = true ;
105+ DevelopmentEnabled = true ;
106+
148107 MessageBox . Show ( this , "Sideloading activated!" , "Success!" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
108+
149109 UpdatePolicyState ( ) ;
150110 }
151111 catch ( Exception ex )
152112 {
153- MessageBox . Show ( this , ex . Message , "Error while activating sideloading!" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
113+ if ( ex is COMException && ( ( uint ) ( ( COMException ) ex ) . ErrorCode ) == 0xC004F014 )
114+ MessageBox . Show ( this , "You likely ran out of storage or something else caused your tokens.dat to get corrupted. SPPSVC will recreate it. Try rebooting to let Windows reactivate itself before trying again. Make sure you have at least 30MB free before using Sideloading Unlocker." , "The key was recognised but I can't activate it." , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
115+ else MessageBox . Show ( this , ex . Message , "Error while activating sideloading!" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
154116 }
155117 }
156118
0 commit comments