@@ -284,8 +284,8 @@ public string RestartExecutablePath
284
284
/// This is the name that will be used/started when the update has been installed.
285
285
/// This defaults to <see cref="Environment.CommandLine"/>.
286
286
/// Used in conjunction with RestartExecutablePath to restart the application --
287
- /// {RestartExecutablePath}/{RestartExecutableName} is what is called to restart the
288
- /// app.
287
+ /// cd " {RestartExecutablePath}"
288
+ /// "{RestartExecutableName}" is what is called to restart the app.
289
289
/// </summary>
290
290
public string RestartExecutableName
291
291
{
@@ -295,7 +295,20 @@ public string RestartExecutableName
295
295
{
296
296
return _restartExecutableName ;
297
297
}
298
- return Environment . CommandLine ;
298
+ #if NETCORE
299
+ try
300
+ {
301
+ return Path . GetFileName ( System . Diagnostics . Process . GetCurrentProcess ( ) . MainModule . FileName ) ;
302
+ }
303
+ catch ( Exception e )
304
+ {
305
+ LogWriter ? . PrintMessage ( "Unable to get executable name: " + e . Message ) ;
306
+ }
307
+ #endif
308
+ // we cannot just use Path.GetFileName because on .NET Framework it can fail with
309
+ // invalid chars in the path, so we do some crazy things to get the file name anotehr way
310
+ var cmdLine = Environment . CommandLine . Trim ( ) . TrimStart ( '"' ) . TrimEnd ( '"' ) ;
311
+ return cmdLine . Substring ( cmdLine . LastIndexOf ( Path . DirectorySeparatorChar ) + 1 ) . Trim ( ) ;
299
312
}
300
313
set
301
314
{
@@ -415,7 +428,7 @@ public IAppCastHandler AppCastHandler
415
428
set => _appCastHandler = value ;
416
429
}
417
430
418
- #endregion
431
+ #endregion
419
432
420
433
/// <summary>
421
434
/// Starts a SparkleUpdater background loop to check for updates every 24 hours.
@@ -569,7 +582,7 @@ private void UnregisterEvents()
569
582
}
570
583
}
571
584
572
- #endregion
585
+ #endregion
573
586
574
587
/// <summary>
575
588
/// This method checks if an update is required. During this process the appcast
@@ -1306,6 +1319,13 @@ protected virtual async Task RunDownloadedInstaller(string downloadFilePath)
1306
1319
LogWriter . PrintMessage ( "Generating batch in {0}" , Path . GetFullPath ( batchFilePath ) ) ;
1307
1320
1308
1321
string processID = Process . GetCurrentProcess ( ) . Id . ToString ( ) ;
1322
+ string relaunchAfterUpdate = "" ;
1323
+ if ( RelaunchAfterUpdate )
1324
+ {
1325
+ relaunchAfterUpdate = $@ "
1326
+ cd ""{ workingDir } ""
1327
+ ""{ executableName } """;
1328
+ }
1309
1329
1310
1330
using (FileStream stream = new FileStream(batchFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 4096, true))
1311
1331
using (StreamWriter write = new StreamWriter(stream, new UTF8Encoding(false))/*new StreamWriter(batchFilePath, false, new UTF8Encoding(false))*/)
@@ -1315,13 +1335,6 @@ protected virtual async Task RunDownloadedInstaller(string downloadFilePath)
1315
1335
// We should wait until the host process has died before starting the installer.
1316
1336
// This way, any DLLs or other items can be replaced properly.
1317
1337
// Code from: http://stackoverflow.com/a/22559462/3938401
1318
- string relaunchAfterUpdate = "" ;
1319
- if ( RelaunchAfterUpdate )
1320
- {
1321
- relaunchAfterUpdate = $@ "
1322
- cd ""{ workingDir } ""
1323
- ""{ executableName } """;
1324
- }
1325
1338
1326
1339
string output = $@"
1327
1340
@echo off
@@ -1360,11 +1373,6 @@ setlocal ENABLEDELAYEDEXPANSION
1360
1373
fi;
1361
1374
done;
1362
1375
" ;
1363
- string relaunchAfterUpdate = "" ;
1364
- if ( RelaunchAfterUpdate )
1365
- {
1366
- relaunchAfterUpdate = Path . Combine ( workingDir , executableName ) ;
1367
- }
1368
1376
if ( IsZipDownload ( downloadFilePath ) ) // .zip on macOS or .tar.gz on Linux
1369
1377
{
1370
1378
// waiting for finish based on http://blog.joncairns.com/2013/03/wait-for-a-unix-process-to-finish/
0 commit comments