Browse Source

Portable installer fixes...

Turns out you can't set the last access time on a directory.
Shocker.

Unfortunately this will stop portable users upgrading from 1.1.1
Antony Male 10 years ago
parent
commit
b4c32019ed

+ 26 - 10
src/PortableInstaller/Program.cs

@@ -66,15 +66,23 @@ namespace PortableInstaller
                 if (destinationExists)
                 {
                     movedDestinationPath = GenerateBackupDestinationPath(destinationPath);
-                    Console.WriteLine($"Moving {destinationPath} to {movedDestinationPath}");
-                    try
-                    {
-                        Directory.Move(destinationPath, movedDestinationPath);
-                    }
-                    catch (Exception)
+                    while (true)
                     {
-                        Console.WriteLine($"!! Unable to move {destinationPath} to {movedDestinationPath}. Your files have not been altered.");
-                        throw;
+                        Console.WriteLine($"Moving {destinationPath} to {movedDestinationPath}");
+                        try
+                        {
+                            Directory.Move(destinationPath, movedDestinationPath);
+                            break;
+                        }
+                        catch (Exception e)
+                        {
+                            Console.WriteLine();
+                            Console.WriteLine($"!! Unable to move {destinationPath} to {movedDestinationPath} ({e.GetType().Name} {e.Message})");
+                            Console.WriteLine($"!! Please make sure that {destinationPath}, or any of the files inside it, aren't open.");
+                            Console.WriteLine($"!! Press any key to try again, or Ctrl-C to abort the upgrade.");
+                            Console.WriteLine($"!! If you abort the upgrade, none of your files will be modified.");
+                            Console.ReadKey();
+                        }
                     }
                 }
 
@@ -85,6 +93,7 @@ namespace PortableInstaller
                 }
                 catch (Exception)
                 {
+                    Console.WriteLine();
                     Console.WriteLine($"!! Unable to move {sourcePath} to {destinationPath}. Your copy of SyncTrayzor is at {sourcePath}.");
                     throw;
                 }
@@ -95,6 +104,7 @@ namespace PortableInstaller
                     var destDataFolder = Path.Combine(destinationPath, "data");
                     if (Directory.Exists(sourceDataFolder))
                     {
+                        Console.WriteLine();
                         Console.WriteLine($"Copying data folder {sourceDataFolder} to {destDataFolder}...");
                         try
                         {
@@ -102,12 +112,14 @@ namespace PortableInstaller
                         }
                         catch (Exception)
                         {
+                            Console.WriteLine();
                             Console.WriteLine($"!! Unable to copy {sourceDataFolder} to {destDataFolder}. Your copy of SyncTrayzor is at {movedDestinationPath}, and will still work.");
                             throw;
                         }
                     }
                     else
                     {
+                        Console.WriteLine();
                         Console.WriteLine($"!! Could not find source data folder {sourceDataFolder}, so not copying. If you have ever started SyncTrayzor from {movedDestinationPath}, this is an error: please manually copy your 'data' folder from whereever it is to {destDataFolder}");
                         pauseAtEnd = true;
                     }
@@ -124,7 +136,8 @@ namespace PortableInstaller
                         }
                         catch (Exception e)
                         {
-                            Console.WriteLine($"Unable to increase install count: {e.GetType().Name} {e.Message}. Continuing anyway.");
+                            Console.WriteLine();
+                            Console.WriteLine($"!! Unable to increase install count: {e.GetType().Name} {e.Message}. Continuing anyway.");
                             pauseAtEnd = true;
                         }
                     }
@@ -137,7 +150,8 @@ namespace PortableInstaller
                         }
                         catch (Exception e)
                         {
-                            Console.WriteLine($"Unable to set install count: {e.GetType().Name} {e.Message}. Continuing anyway.");
+                            Console.WriteLine();
+                            Console.WriteLine($"!! Unable to set install count: {e.GetType().Name} {e.Message}. Continuing anyway.");
                             pauseAtEnd = true;
                         }
                     }
@@ -149,6 +163,7 @@ namespace PortableInstaller
                     }
                     catch (Exception e)
                     {
+                        Console.WriteLine();
                         Console.WriteLine($"!! Unable to delete your old installation at {movedDestinationPath} ({e.GetType().Name} {e.Message}). Your new installation is at {destinationPath}, and should be fully functional. Please double-check, and manually delete {movedDestinationPath}.");
                         pauseAtEnd = true;
                     }
@@ -156,6 +171,7 @@ namespace PortableInstaller
 
                 if (pauseAtEnd)
                 {
+                    Console.WriteLine();
                     Console.WriteLine();
                     Console.WriteLine("One or more warnings occurred. Please review the messages above, and take any appropriate action.");
                     Console.WriteLine("Press any key to continue (this will restart SyncTrayzor)");

+ 0 - 3
src/SyncTrayzor/Services/UpdateManagement/PortableUpdateVariantHandler.cs

@@ -112,9 +112,6 @@ namespace SyncTrayzor.Services.UpdateManagement
 
             await Task.Run(() => ZipFile.ExtractToDirectory(zipPath, destinationDir));
 
-            // Touch the folder, so we (or someone else!) doesn't delete when cleaning up
-            this.filesystem.SetLastAccessTimeUtc(destinationDir, DateTime.UtcNow);
-
             // We expect a single folder inside the extracted dir, called e.g. SyncTrayzorPortable-x86
             var children = this.filesystem.GetDirectories(destinationDir);
             if (children.Length != 1)

+ 10 - 1
src/SyncTrayzor/Services/UpdateManagement/UpdateDownloader.cs

@@ -83,7 +83,14 @@ namespace SyncTrayzor.Services.UpdateManagement
                     if (initialValidationResult.Item1)
                     {
                         // Touch the file, so we (or someone else!) doesn't delete when cleaning up
-                        this.filesystemProvider.SetLastAccessTimeUtc(downloadPath, DateTime.UtcNow);
+                        try
+                        {
+                            this.filesystemProvider.SetLastAccessTimeUtc(downloadPath, DateTime.UtcNow);
+                        }
+                        catch (Exception e)
+                        {
+                            logger.Warn($"Failed to set last access time on {downloadPath}", e);
+                        }
 
                         // EXIT POINT
                         return initialValidationResult;
@@ -167,6 +174,8 @@ namespace SyncTrayzor.Services.UpdateManagement
 
         private void CleanUpUnusedFiles()
         {
+            // TODO: Delete extracted portable dir?
+
             var threshold = DateTime.UtcNow - fileMaxAge;
 
             foreach (var file in this.filesystemProvider.GetFiles(this.downloadsDir))