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

Commit

Permalink
FIX: Fix updater
Browse files Browse the repository at this point in the history
  • Loading branch information
bunkerskyi committed Jul 4, 2016
1 parent 857ccf2 commit 23e9f6d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/Gui/WinFormsGui/Properties/AssemblyInfo.cs
Expand Up @@ -35,5 +35,5 @@
// используя "*", как показано ниже:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("1.4.1.0")]
[assembly: AssemblyFileVersion("1.4.1.0")]
[assembly: AssemblyVersion("1.4.2.0")]
[assembly: AssemblyFileVersion("1.4.2.0")]
4 changes: 2 additions & 2 deletions src/KryBot.Core/Properties/AssemblyInfo.cs
Expand Up @@ -35,5 +35,5 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
54 changes: 4 additions & 50 deletions src/KryBot.Core/Updater.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.IO.Compression;
Expand Down Expand Up @@ -47,35 +46,25 @@ public static async Task<Log> Update()
try
{
GitHunReleaseAssets archive = null;
GitHunReleaseAssets singleFile = null;

DeleteTempFiles();
var release = await GetGitHubRelease();

foreach (var asset in release.Assets)
{
if (asset.Name == FilePaths.KryBot)
if(asset.Name == FilePaths.KryBotArchive)
{
archive = asset;
}
else if(asset.Name == FilePaths.KryBotArchive)
{
singleFile = asset;
}
}

if (archive == null && singleFile == null)
if (archive == null)
{
return new Log(strings.Updater_Update_UpdateFailed, Color.Red, false);
}

if (singleFile != null)
{
return await UpdatefromFile(singleFile);
}
else
{
return await UpdateFromArchive(archive);
return await UpdateFromArchive(archive);
}
}
catch (JsonReaderException)
Expand All @@ -90,34 +79,6 @@ public static async Task<Log> Update()
}
}

private static async Task<Log> UpdatefromFile(GitHunReleaseAssets asset)
{
var stream = new WebClient().OpenRead(asset.DownloadUrl);
if (stream != null)
{
using (var fileStream = File.Open(FilePaths.KryBotNew, FileMode.Create))
{
await stream.CopyToAsync(fileStream);
}

File.Move(FilePaths.KryBot, FilePaths.KryBotOld);

try
{
File.Move(FilePaths.KryBotNew, FilePaths.KryBot);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
File.Move(FilePaths.KryBotOld, FilePaths.KryBot);
DeleteTempFiles();
return new Log(strings.Updater_Update_UpdateFailed, Color.Red, false);
}
return new Log(strings.Updater_Update_UpdateDone, Color.Green, true);
}
return new Log(strings.Updater_Update_UpdateFailed, Color.Red, true);
}

private static async Task<Log> UpdateFromArchive(GitHunReleaseAssets asset)
{
List<string> filesToMove = new List<string>();
Expand All @@ -129,35 +90,28 @@ private static async Task<Log> UpdateFromArchive(GitHunReleaseAssets asset)
await stream.CopyToAsync(fileStream);
}

Debug.WriteLine("Exstract strat");
foreach (var entry in ZipFile.OpenRead(FilePaths.KryBotArchive).Entries)
{
if (File.Exists(entry.FullName))
{
Debug.WriteLine($"Exstract: {entry.FullName}.new");
entry.ExtractToFile($"{entry.FullName}.new");
Debug.WriteLine($"Move: {entry.FullName} to {entry.FullName}.old");
File.Move(entry.FullName, $"{entry.FullName}.old");
filesToMove.Add(entry.FullName);
}
else
{
Debug.WriteLine($"Exstract: {entry.FullName}");
entry.ExtractToFile(entry.FullName);
}
}
Debug.WriteLine("Exstract end");

Debug.WriteLine("Move start");
if (filesToMove.Count > 0)
{
foreach (var file in filesToMove)
{
Debug.WriteLine($"Move: {file}.new to {file}");
File.Move($"{file}.new", file);
}
}
Debug.WriteLine("Move end");

return new Log(strings.Updater_Update_UpdateDone, Color.Green, true);

}
Expand Down

0 comments on commit 23e9f6d

Please sign in to comment.