Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
Fixed updater to work properly (hopefully)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueSkrillor committed Jan 20, 2016
1 parent b00a057 commit 66d8152
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
29 changes: 20 additions & 9 deletions VUUpdate/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@ class Program
return new Version(versionInfo.ProductVersion);
}
}
private static string BaseDir
{
get
{
return AppDomain.CurrentDomain.BaseDirectory;
}
}

static void Main(string[] args)
{
bool performedUpdate;
do
{
performedUpdate = false;
for (int versionType = 0; versionType < 4 || performedUpdate; versionType++)
for (int versionType = 0; versionType < 4 && !performedUpdate; versionType++)
{
Console.WriteLine("Checking for new update, VersionType: " + versionType);
if (CheckForUpdate((VersionTypes)versionType))
Expand All @@ -44,22 +51,26 @@ private static void PerformUpdate(VersionTypes newVersionType)
{
KillProcessIfRunning();
DownloadAndApplyUpdate(newVersionType);
Process.Start("./Vertretungsplan_Uploader.exe");
Process.Start(BaseDir + "Vertretungsplan_Uploader.exe");
}

private static void DownloadAndApplyUpdate(VersionTypes newVersionType)
{
WebClient downloadClient = new WebClient();
downloadClient.DownloadFile(string.Format(urlBase, GetNewVersion(newVersionType)), "./temp.zip");
downloadClient.DownloadFile(string.Format(urlBase, GetNewVersion(newVersionType)), BaseDir + "temp.zip");
Console.WriteLine("Update downloaded successfully");

ZipFile.ExtractToDirectory("./temp.zip", "temp");
foreach(string filename in Directory.GetFiles("./temp"))
ZipFile.ExtractToDirectory(BaseDir + "temp.zip", "temp");
File.Delete(BaseDir + "temp.zip");

foreach(string filename in Directory.GetFiles(BaseDir + "temp"))
{
if (File.Exists("./" + filename))
File.Delete("./" + filename);
File.Move("./temp/" + filename, "./" + filename);
Console.WriteLine("Successfully updated " + filename);
var path = filename.Split('\\');
var file = path[path.Length - 1];
if (File.Exists(BaseDir + file))
File.Delete(BaseDir + file);
File.Move(filename, BaseDir + file);
Console.WriteLine("Successfully updated " + file);
}
Directory.Delete("./temp");
Console.WriteLine("Update completed");
Expand Down
5 changes: 2 additions & 3 deletions Vertretungsplan_Uploader/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public partial class MainWindow : MetroWindow

public MainWindow()
{
UpdateChecker_Elapsed(null, null);
InitializeComponent();

notifyIcon = new NotifyIcon();
Expand All @@ -46,8 +45,8 @@ public MainWindow()

private void UpdateChecker_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (File.Exists("./VUUpdater.exe"))
Process.Start("./VUUpdater.exe");
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "VUUpdate.exe"))
Process.Start(AppDomain.CurrentDomain.BaseDirectory + "VUUpdate.exe");
else
AppendMessageToLog("Es wurde kein Updater gefunden!");
}
Expand Down

0 comments on commit 66d8152

Please sign in to comment.