11using System ;
22using System . IO ;
33using Microsoft . Win32 ;
4- using System . Text . Json ;
54using System . Diagnostics ;
65using System . Windows . Forms ;
76using System . IO . Compression ;
87using System . Threading . Tasks ;
98using System . Collections . Generic ;
109using CodeRedLauncher . Controls ;
10+ using System . Configuration ;
1111
1212namespace CodeRedLauncher
1313{
@@ -23,15 +23,27 @@ private void MainFrm_Load(object sender, EventArgs e)
2323 StartupRoutine ( ) ;
2424 }
2525
26- private void TitleBar_OnMinimized ( object sender , EventArgs e )
26+ private void MainFrm_Resize ( object sender , EventArgs e )
2727 {
28- if ( Configuration . ShouldHideWhenMinimized ( ) )
28+ if ( this . WindowState == FormWindowState . Minimized )
2929 {
30- this . Hide ( ) ;
30+ TitleBar_OnMinimized ( null , null ) ;
3131 }
32- else
32+ }
33+
34+ private void TitleBar_OnMinimized ( object sender , EventArgs e )
35+ {
36+ if ( true )
3337 {
34- this . WindowState = FormWindowState . Minimized ;
38+ if ( Configuration . ShouldHideWhenMinimized ( ) )
39+ {
40+ this . Hide ( ) ;
41+ }
42+ else if ( this . WindowState != FormWindowState . Minimized )
43+ {
44+ this . Show ( ) ;
45+ this . WindowState = FormWindowState . Minimized ;
46+ }
3547 }
3648 }
3749
@@ -278,6 +290,72 @@ private void InjectionTimeoutBx_OnValueChanged(object sender, EventArgs e)
278290 }
279291 }
280292
293+ // https://learn.microsoft.com/en-us/dotnet/standard/io/how-to-copy-directories
294+ static void CopyDirectory ( string sourceDir , string destinationDir , bool bRecursive )
295+ {
296+ DirectoryInfo sourceInfo = new DirectoryInfo ( sourceDir ) ;
297+ DirectoryInfo [ ] dirs = sourceInfo . GetDirectories ( ) ;
298+ Directory . CreateDirectory ( destinationDir ) ;
299+
300+ foreach ( FileInfo file in sourceInfo . GetFiles ( ) )
301+ {
302+ string targetFilePath = Path . Combine ( destinationDir , file . Name ) ;
303+ file . CopyTo ( targetFilePath ) ;
304+ }
305+
306+ if ( bRecursive )
307+ {
308+ foreach ( DirectoryInfo subDir in dirs )
309+ {
310+ string newDestinationDir = Path . Combine ( destinationDir , subDir . Name ) ;
311+ CopyDirectory ( subDir . FullName , newDestinationDir , true ) ;
312+ }
313+ }
314+ }
315+
316+ private void InstallPathBtn_OnButtonClick ( object sender , EventArgs e )
317+ {
318+ Architecture . Path modulePath = Storage . GetModulePath ( ) ;
319+
320+ if ( modulePath . Exists ( ) )
321+ {
322+ Architecture . Path newPath = new Architecture . Path ( ) ;
323+ FolderBrowserDialog folderBrowser = new FolderBrowserDialog ( ) ;
324+
325+ if ( folderBrowser . ShowDialog ( ) == DialogResult . OK )
326+ {
327+ newPath = new Architecture . Path ( folderBrowser . SelectedPath ) ;
328+
329+ if ( newPath . Exists ( ) )
330+ {
331+ if ( ! newPath . GetPath ( ) . Contains ( "CodeRed" ) )
332+ {
333+ newPath . Append ( "CodeRed" ) . CreateDirectory ( ) ;
334+ }
335+ }
336+
337+ Logger . Write ( "User selected \" " + folderBrowser . SelectedPath + "\" for new install path." ) ;
338+ }
339+
340+ if ( newPath . Exists ( ) )
341+ {
342+ CopyDirectory ( modulePath . GetPath ( ) , newPath . GetPath ( ) , true ) ;
343+ Directory . Delete ( modulePath . GetPath ( ) , true ) ;
344+
345+ Installer . ModifyRegistry ( false , newPath ) ;
346+ Configuration . Invalidate ( true ) ;
347+ Storage . Invalidate ( true ) ;
348+ ConfigToInterface ( ) ;
349+ StorageToInterface ( ) ;
350+ }
351+ else
352+ {
353+ Logger . Write ( "Selected path is invalid, cannot move install path!" , LogLevel . LEVEL_ERROR ) ;
354+ MessageBox . Show ( "Selected path is invalid, cannot move install path!" , Assembly . GetTitle ( ) ) ;
355+ }
356+ }
357+ }
358+
281359 private void OpenFolderBtn_OnButtonClick ( object sender , EventArgs e )
282360 {
283361 Architecture . Path folderPath = Storage . GetModulePath ( ) ;
@@ -632,9 +710,7 @@ private async void StartupRoutine(bool bInvalidate = false)
632710
633711 if ( await Retrievers . CheckInitialized ( ) )
634712 {
635- string pingUrl = await Retrievers . GetModuleUrl ( ) ;
636-
637- if ( await Downloaders . WebsiteOnline ( pingUrl ) == false )
713+ if ( await Downloaders . WebsiteOnline ( Retrievers . GetRemoteURL ( ) ) == false )
638714 {
639715 OfflinePopupCtrl . Show ( ) ;
640716 }
@@ -762,6 +838,7 @@ private void StorageToInterface()
762838
763839 LaunchBtn . Visible = true ;
764840 ManualInjectBtn . Visible = false ;
841+ InstallPathBx . DisplayText = Storage . GetModulePath ( ) . GetPath ( ) ;
765842 }
766843 }
767844
@@ -915,13 +992,13 @@ private async void InstallPopupCtrl_DoubleFirstButtonClick(object sender, EventA
915992 else if ( moduleReport . FailReason != null )
916993 {
917994 Logger . Write ( moduleReport . FailReason , LogLevel . LEVEL_ERROR ) ;
918- MessageBox . Show ( moduleReport . FailReason ) ;
995+ MessageBox . Show ( moduleReport . FailReason , Assembly . GetTitle ( ) ) ;
919996 }
920997 }
921998 else if ( pathReport . FailReason != null )
922999 {
9231000 Logger . Write ( pathReport . FailReason , LogLevel . LEVEL_ERROR ) ;
924- MessageBox . Show ( pathReport . FailReason ) ;
1001+ MessageBox . Show ( pathReport . FailReason , Assembly . GetTitle ( ) ) ;
9251002 }
9261003 }
9271004
@@ -943,13 +1020,13 @@ private async void InstallPopupCtrl_DoubleSecondButtonClick(object sender, Event
9431020 else if ( moduleReport . FailReason != null )
9441021 {
9451022 Logger . Write ( moduleReport . FailReason , LogLevel . LEVEL_ERROR ) ;
946- MessageBox . Show ( moduleReport . FailReason ) ;
1023+ MessageBox . Show ( moduleReport . FailReason , Assembly . GetTitle ( ) ) ;
9471024 }
9481025 }
9491026 else if ( pathReport . FailReason != null )
9501027 {
9511028 Logger . Write ( pathReport . FailReason , LogLevel . LEVEL_ERROR ) ;
952- MessageBox . Show ( pathReport . FailReason ) ;
1029+ MessageBox . Show ( pathReport . FailReason , Assembly . GetTitle ( ) ) ;
9531030 }
9541031 }
9551032
@@ -975,7 +1052,6 @@ private async void UpdatePopupCtrl_DoubleSecondButtonClick(object sender, EventA
9751052 {
9761053 UpdatePopupCtrl . Hide ( ) ;
9771054 ProcessTmr . Start ( ) ;
978- this . TopMost = false ;
9791055 CheckForUpdates ( true , false ) ;
9801056 }
9811057 else if ( report . FailReason != null )
0 commit comments