Skip to content

Commit

Permalink
Merge branch 'release/1.1.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
canton7 committed Feb 8, 2016
2 parents f08f1bb + 8d76891 commit a0b2d83
Show file tree
Hide file tree
Showing 22 changed files with 468 additions and 263 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

v1.1.7
------

- Handle thousands of conflicts in the conflict editor without crashing (#224)
- Handle crash when syncing many files (reappearance of #112) (#227)
- Fix rendering of some strings
- Add logging to file to portable upgrades, in case of error

v1.1.6
------

Expand Down
5 changes: 3 additions & 2 deletions server/version_check.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function get_with_wildcard($src, $value, $default = null)
}

$versions = [
'1.1.6' => [
'1.1.7' => [
'installed' => [
'direct_download_url' => [
'x64' => 'https://github.com/canton7/SyncTrayzor/releases/download/v{version}/SyncTrayzorSetup-x64.exe',
Expand All @@ -80,11 +80,12 @@ function get_with_wildcard($src, $value, $default = null)
],
'sha1sum_download_url' => 'https://github.com/canton7/SyncTrayzor/releases/download/v{version}/sha1sum.txt.asc',
'release_page_url' => 'https://github.com/canton7/SyncTrayzor/releases/tag/v{version}',
'release_notes' => "- Fix portable installer where TEMP is on a different drive to SyncTrayzor (#218)\n- Fix bug where 'Save' button wouldn't be enabled in Syncthing's 'Add/Edit Folder' pane, after using the 'Browse' button (#219)\n- Fix race crash (#221)\n- Don't force Syncthing to use https (should fix #201)\n- Handle problems getting the icon for a file (should fix #224)\n- Improve help output of ProcessRunner.exe (#223)",
'release_notes' => "- Handle thousands of conflicts in the conflict editor without crashing (#224)\n- Handle crash when syncing many files (reappearance of #112) (#227)\n- Fix rendering of some strings\n- Add logging to file to portable upgrades, in case of error",
]
];

$upgrades = [
'1.1.6' => ['to' => 'latest', 'formatter' => '4'],
'1.1.5' => ['to' => 'latest', 'formatter' => '4'],
'1.1.4' => ['to' => 'latest', 'formatter' => '4'],
'1.1.3' => ['to' => 'latest', 'formatter' => '4'],
Expand Down
119 changes: 68 additions & 51 deletions src/PortableInstaller/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,29 @@ namespace PortableInstaller
{
class Program
{
static int Main(string[] args)
{
RecycleBinDeleter.Logger = s => Console.WriteLine("!! " + s);
private static readonly List<string> logMessages = new List<string>();

public static int Main(string[] args)
{
RecycleBinDeleter.Logger = s => Log("!! " + s);
if (args.Length != 4)
{
Console.WriteLine("You should not invoke this executable directly. It is used as part of the automatic upgrade process for portable installations.");
Console.ReadKey();
return 0;
}

var destinationPath = args[0];
var sourcePath = args[1];
var waitForPid = Int32.Parse(args[2]);
var pathToRestartApplication = args[3];
var destinationPathParent = Path.GetDirectoryName(destinationPath);

try
{
var destinationPath = args[0];
var sourcePath = args[1];
var waitForPid = Int32.Parse(args[2]);
var pathToRestartApplication = args[3];

bool pauseAtEnd = false;

Console.WriteLine("Waiting for SyncTrayzor process to exit...");
Log("Waiting for SyncTrayzor process to exit...");
try
{
using (var process = Process.GetProcessById(waitForPid))
Expand All @@ -43,22 +46,21 @@ static int Main(string[] args)
{ }

// By default our CWD is the destinationPath, which locks it
var cwd = Path.GetDirectoryName(destinationPath);
try
{
Directory.SetCurrentDirectory(cwd);
Directory.SetCurrentDirectory(destinationPathParent);
}
catch (Exception)
{
Console.WriteLine($"!! Unable to set working directory to\n {cwd}.\nNone of your files have been touched.");
Log($"!! Unable to set working directory to\n {destinationPathParent}.\nNone of your files have been touched.");
throw;
}

var destinationExists = Directory.Exists(destinationPath);

if (!Directory.Exists(sourcePath))
{
Console.WriteLine($"!! Unable to find source path\n {sourcePath}.\nThis is a bug with SyncTrayzor's upgrade mechanism.");
Log($"!! Unable to find source path\n {sourcePath}.\nThis is a bug with SyncTrayzor's upgrade mechanism.");
throw new Exception("Unable to find source path");
}

Expand All @@ -68,34 +70,34 @@ static int Main(string[] args)
movedDestinationPath = GenerateBackupDestinationPath(destinationPath);
while (true)
{
Console.WriteLine($"Moving\n {destinationPath}\nto\n {movedDestinationPath}");
Log($"Moving\n {destinationPath}\nto\n {movedDestinationPath}");
try
{
DirectoryMove(destinationPath, movedDestinationPath);
break;
}
catch (Exception e)
{
Console.WriteLine();
Console.WriteLine($"!! Unable to move\n {destinationPath}\nto\n {movedDestinationPath}");
Console.WriteLine($"Error: {e.GetType().Name} {e.Message}");
Console.WriteLine($"!! Please make sure that\n {destinationPath}\nor 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.");
Log();
Log($"!! Unable to move\n {destinationPath}\nto\n {movedDestinationPath}");
Log($"Error: {e.GetType().Name} {e.Message}");
Log($"!! Please make sure that\n {destinationPath}\nor any of the files inside it, aren't open.");
Log($"!! Press any key to try again, or Ctrl-C to abort the upgrade.");
Log($"!! If you abort the upgrade, none of your files will be modified.");
Console.ReadKey();
}
}
}

Console.WriteLine($"Moving\n {sourcePath}\nto\n {destinationPath}");
Log($"Moving\n {sourcePath}\nto\n {destinationPath}");
try
{
DirectoryMove(sourcePath, destinationPath);
}
catch (Exception)
{
Console.WriteLine();
Console.WriteLine($"!! Unable to move\n {sourcePath}\nto\n {destinationPath}.\nYour copy of SyncTrayzor is at\n {sourcePath}\nand will still work.");
Log();
Log($"!! Unable to move\n {sourcePath}\nto\n {destinationPath}.\nYour copy of SyncTrayzor is at\n {sourcePath}\nand will still work.");
throw;
}

Expand All @@ -105,23 +107,23 @@ static int Main(string[] args)
var destDataFolder = Path.Combine(destinationPath, "data");
if (Directory.Exists(sourceDataFolder))
{
Console.WriteLine();
Console.WriteLine($"Copying data folder\n {sourceDataFolder}\nto\n {destDataFolder}...");
Log();
Log($"Copying data folder\n {sourceDataFolder}\nto\n {destDataFolder}...");
try
{
DirectoryCopy(sourceDataFolder, destDataFolder);
}
catch (Exception)
{
Console.WriteLine();
Console.WriteLine($"!! Unable to copy\n {sourceDataFolder}\nto\n {destDataFolder}.\nYour copy of SyncTrayzor is at\n {movedDestinationPath}\nand will still work.");
Log();
Log($"!! Unable to copy\n {sourceDataFolder}\nto\n {destDataFolder}.\nYour copy of SyncTrayzor is at\n {movedDestinationPath}\nand 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}");
Log();
Log($"!! 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;
}

Expand All @@ -130,70 +132,72 @@ static int Main(string[] args)
if (File.Exists(sourceInstallCount))
{
var installCount = Int32.Parse(File.ReadAllText(sourceInstallCount).Trim());
Console.WriteLine($"Increasing install count to {installCount + 1} from\n {sourceInstallCount}\nto\n {destInstallCount}");
Log($"Increasing install count to {installCount + 1} from\n {sourceInstallCount}\nto\n {destInstallCount}");
try
{
File.WriteAllText(destInstallCount, (installCount + 1).ToString());
}
catch (Exception e)
{
Console.WriteLine();
Console.WriteLine($"!! Unable to increase install count: {e.GetType().Name} {e.Message}. Continuing anyway.");
Log();
Log($"!! Unable to increase install count: {e.GetType().Name} {e.Message}. Continuing anyway.");
pauseAtEnd = true;
}
}
else
{
Console.WriteLine($"{sourceInstallCount}\ndoesn't exist, so setting installCount to 1 in\n {destInstallCount}");
Log($"{sourceInstallCount}\ndoesn't exist, so setting installCount to 1 in\n {destInstallCount}");
try
{
File.WriteAllText(destInstallCount, "1");
}
catch (Exception e)
{
Console.WriteLine();
Console.WriteLine($"!! Unable to set install count: {e.GetType().Name} {e.Message}. Continuing anyway.");
Log();
Log($"!! Unable to set install count: {e.GetType().Name} {e.Message}. Continuing anyway.");
pauseAtEnd = true;
}
}

Console.WriteLine($"Deleting\n {movedDestinationPath}\nto the recycle bin");
Log($"Deleting\n {movedDestinationPath}\nto the recycle bin");
try
{
RecycleBinDeleter.Delete(movedDestinationPath);
}
catch (Exception e)
{
Console.WriteLine();
Console.WriteLine($"!! Unable to delete your old installation at\n {movedDestinationPath}\n Error: {e.GetType().Name} {e.Message}.");
Console.WriteLine($"Your new installation is at\n {destinationPath}\nand should be fully functional.");
Console.WriteLine($"Please double-check, and manually delete\n {movedDestinationPath}.");
Log();
Log($"!! Unable to delete your old installation at\n {movedDestinationPath}\n Error: {e.GetType().Name} {e.Message}.");
Log($"Your new installation is at\n {destinationPath}\nand should be fully functional.");
Log($"Please double-check, and manually delete\n {movedDestinationPath}.");
pauseAtEnd = true;
}
}

if (pauseAtEnd)
{
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("One or more warnings occurred. Please review the messages above, and take any appropriate action.");
Log();
Log();
Log("One or more warnings occurred. Please review the messages above, and take any appropriate action.");
WriteLogToFile(destinationPathParent);
Console.WriteLine("Press any key to continue (this will restart SyncTrayzor)");
Console.ReadKey();
}

Console.WriteLine($"Restarting application {pathToRestartApplication}");
Log($"Restarting application {pathToRestartApplication}");
Process.Start(pathToRestartApplication);

return 0;
}
catch (Exception e)
{
Console.WriteLine();
Console.WriteLine($"--- An error occurred ---");
Console.WriteLine($"{e.GetType().Name}: {e.Message}");
Console.WriteLine();
Console.WriteLine("The upgrade failed to complete successfully. Sorry about that.");
Console.WriteLine("Please read the messages above.");
Log();
Log($"--- An error occurred ---");
Log($"{e.GetType().Name}: {e.Message}");
Log();
Log("The upgrade failed to complete successfully. Sorry about that.");
Log("Please read the messages above.");
WriteLogToFile(destinationPathParent);
Console.WriteLine("Press any key to continue");
Console.ReadKey();
return 2;
Expand Down Expand Up @@ -222,7 +226,7 @@ private static void DirectoryCopy(string sourceDirName, string destDirName)

if (!dir.Exists)
throw new DirectoryNotFoundException($"Source directory does not exist or could not be found: {sourceDirName}");

DirectoryInfo[] dirs = dir.GetDirectories();
// If the destination directory doesn't exist, create it.
if (!Directory.Exists(destDirName))
Expand Down Expand Up @@ -256,5 +260,18 @@ private static void DirectoryMove(string sourceDirName, string destDirName)
Directory.Delete(sourceDirName, true);
}
}

private static void Log(string message = "")
{
Console.WriteLine(message);
logMessages.Add(message);
}

private static void WriteLogToFile(string path)
{
var filePath = Path.Combine(path, "SyncTrayzorUpgradeErrorLog.txt");
Console.WriteLine($"This log has been written to:\n {filePath}");
File.WriteAllLines(filePath, logMessages);
}
}
}
Loading

0 comments on commit a0b2d83

Please sign in to comment.