@@ -28,9 +28,11 @@ public partial class AVRControl : Form
2828
2929 private string roamingPath = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) , "AVRControl" , "AVRControl.exe" ) ;
3030 private bool isRunningFromRoaming = false ;
31- private string currentConfigPath ;
31+ private string currentConfigPath = string . Empty ;
3232
33- private readonly string config = Path . GetDirectoryName ( Assembly . GetEntryAssembly ( ) . Location ) + "\\ AVRControl.cfg" ;
33+ private static readonly HttpClient _httpClient = new HttpClient ( ) ;
34+
35+ private readonly string config = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "AVRControl.cfg" ) ;
3436 private bool _muted = false ;
3537 private int CurVol = 10 ;
3638 private bool IsAVROn = false ;
@@ -129,8 +131,8 @@ private void LoadDevice()
129131
130132 try
131133 {
132- string savedIP = ConfigManager . GetValue ( currentConfigPath , "IP" ) ;
133- string savedTray = ConfigManager . GetValue ( currentConfigPath , "Systray" ) ;
134+ string ? savedIP = ConfigManager . GetValue ( currentConfigPath , "IP" ) ;
135+ string ? savedTray = ConfigManager . GetValue ( currentConfigPath , "Systray" ) ;
134136
135137 if ( savedIP != null )
136138 {
@@ -473,7 +475,7 @@ private void btnHeosPlayRepeatOne_MouseEnter(object sender, EventArgs e)
473475 }
474476 private void btnInstall_Click ( object sender , EventArgs e )
475477 {
476- string targetDir = Path . GetDirectoryName ( roamingPath ) ;
478+ string ? targetDir = Path . GetDirectoryName ( roamingPath ) ;
477479 string registryPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run" ;
478480
479481 try
@@ -498,12 +500,15 @@ private void btnInstall_Click(object sender, EventArgs e)
498500 return ;
499501 }
500502
501- if ( ! Directory . Exists ( targetDir ) )
502- Directory . CreateDirectory ( targetDir ) ;
503+ if ( ! string . IsNullOrEmpty ( targetDir ) )
504+ {
505+ if ( ! Directory . Exists ( targetDir ) )
506+ Directory . CreateDirectory ( targetDir ) ;
507+ }
503508
504509 System . IO . File . Copy ( Application . ExecutablePath , roamingPath , true ) ;
505510
506- string targetCfg = Path . Combine ( targetDir , "AVRControl.cfg" ) ;
511+ string targetCfg = Path . Combine ( targetDir ! , "AVRControl.cfg" ) ;
507512 if ( ! System . IO . File . Exists ( targetCfg ) )
508513 {
509514 currentConfigPath = targetCfg ;
@@ -512,7 +517,7 @@ private void btnInstall_Click(object sender, EventArgs e)
512517 ConfigManager . SaveValue ( currentConfigPath , "Systray" , "TRUE" ) ;
513518 }
514519
515- using ( RegistryKey key = Registry . CurrentUser . OpenSubKey ( registryPath , true ) )
520+ using ( RegistryKey ? key = Registry . CurrentUser . OpenSubKey ( registryPath , true ) )
516521 {
517522 if ( key != null ) key . SetValue ( "AVRControl" , $ "\" { roamingPath } \" ") ;
518523 }
@@ -525,7 +530,7 @@ private void btnInstall_Click(object sender, EventArgs e)
525530 }
526531 else if ( btnInstall . Text == "Uninstall" )
527532 {
528- using ( RegistryKey key = Registry . CurrentUser . OpenSubKey ( registryPath , true ) )
533+ using ( RegistryKey ? key = Registry . CurrentUser . OpenSubKey ( registryPath , true ) )
529534 {
530535 if ( key != null ) key . DeleteValue ( "AVRControl" , false ) ;
531536 }
0 commit comments