Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Killers0992 committed Jun 26, 2022
1 parent 24fe67d commit 0e0db06
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 69 deletions.
56 changes: 13 additions & 43 deletions VrcOscIntegrations/Interface/Entries/IntegrationBrowserItem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using System.IO.Compression;
using VrcOscIntegrations.Services;

namespace VrcOscIntegrations.Interface.Entries
{
Expand Down Expand Up @@ -121,6 +122,7 @@ private void interactionButton_Click(object sender, EventArgs e)
{
var browserItem = MainPanel.BrowserIntegrationItems.FirstOrDefault(p => p.Id == Id);


if (browserItem == null) return;

var result = _client.GetAsync(browserItem.VersionFile).Result;
Expand All @@ -139,52 +141,20 @@ private void interactionButton_Click(object sender, EventArgs e)
return;
}

if (!string.IsNullOrEmpty(versionObject.DependenciesFileName))
AutoUpdater.ReadyUpdate = new List<PendingUpdate>()
{
var depFile = $"{browserItem.GithubRepo}/releases/download/{versionObject.Version}/{versionObject.DependenciesFileName}.zip";
var depTargetFile = Path.Combine(Program.TempPath, $"{versionObject.DependenciesFileName}.zip");

result = _client.GetAsync(depFile).Result;
if (!result.IsSuccessStatusCode)
{
Logger.Error("Browser", $"Failed downloading dependencies for {IntegrationName}! ( network failure )", Color.White, Color.White);
return;
}

var bytes = result.Content.ReadAsByteArrayAsync().Result;
File.WriteAllBytes(depTargetFile, bytes);

Logger.Info("Browser", $"Extract all dependencies for {IntegrationName} into dependencies folder...", Color.White, Color.White);

using (ZipArchive archive = ZipFile.OpenRead(depTargetFile))
new PendingUpdate()
{
foreach (ZipArchiveEntry entry in archive.Entries.Where(p => p.Name.EndsWith(".dll")))
{
var depTargetFile2 = Path.Combine(Program.DependenciesPath, $"{entry.Name}.dll");

if (!File.Exists(depTargetFile2))
entry.ExtractToFile(depTargetFile2);
}
Id = Id,
NewVersion = versionObject.Version,
DisplayName = IntegrationName,
GithubRepo = browserItem.GithubRepo,
IntegrationFileName = versionObject.IntegrationFileName,
DependenciesFileName = versionObject.DependenciesFileName,
IsUpdate = false,
Type = UpdateType.Integration,
}
Logger.Info("Browser", $"Extracted all dependencies for {IntegrationName} into dependencies folder!", Color.White, Color.White);

File.Delete(depTargetFile);
}

var mainFile = $"{browserItem.GithubRepo}/releases/download/{versionObject.Version}/{versionObject.IntegrationFileName}.dll";
var mainFileTarget = Path.Combine(Program.IntegrationsPath, $"{versionObject.IntegrationFileName}.dll");

result = _client.GetAsync(mainFile).Result;
if (!result.IsSuccessStatusCode)
{
Logger.Error("Browser", $"Failed downloading main assembly for {IntegrationName}! ( network failure )", Color.White, Color.White);
return;
}

var bytes2 = result.Content.ReadAsByteArrayAsync().Result;
File.WriteAllBytes(mainFileTarget, bytes2);
Logger.Info("Browser", $"Saved main assembly for integration {IntegrationName} into integrations folder!", Color.White, Color.White);
MessageBox.Show($"Installed integration {IntegrationName}, restart application to load new installed integration!");
};
}
}
}
10 changes: 5 additions & 5 deletions VrcOscIntegrations/Interface/MainPanel.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 16 additions & 19 deletions VrcOscIntegrations/Interface/MainPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public partial class MainPanel : PoisonForm
public static bool IsLoaded;
public static PanelVersion CurrentVersion = new PanelVersion()
{
Version = "1.0.4"
Version = "1.0.5"
};

private PoisonTaskWindow _updatesWindow;
Expand Down Expand Up @@ -288,8 +288,7 @@ private void fileDownloader_RunWorkerCompleted(object sender, System.ComponentMo
progressBar.Visible = false;
progressText.Visible = false;

string currentPath = Path.Combine(AppContext.BaseDirectory, $"VrcOscIntegrations.exe");
ProcessStartInfo startInfo = new ProcessStartInfo(currentPath);
ProcessStartInfo startInfo = new ProcessStartInfo(Path.Combine(AppContext.BaseDirectory, $"VrcOscIntegrations.exe"));
Process.Start(startInfo);
Process.GetCurrentProcess().Kill();
}
Expand All @@ -300,25 +299,25 @@ private void fileDownloader_DoWork(object sender, System.ComponentModel.DoWorkEv

for (int x = 0; x < updatesCount; x++)
{
string tempPath =
AutoUpdater.ReadyUpdate[x].Type == UpdateType.Panel ?
Path.Combine(Program.TempPath, $"temp_VrcOscIntegrations.exe") :
Path.Combine(Program.TempPath, $"temp_{AutoUpdater.ReadyUpdate[x].IntegrationFileName}.dll");
string targetPath =
AutoUpdater.ReadyUpdate[x].Type == UpdateType.Panel ?
Path.Combine(AppContext.BaseDirectory, $"VrcOscIntegrations.exe") :
Path.Combine(Program.IntegrationsPath, $"{AutoUpdater.ReadyUpdate[x].IntegrationFileName}.dll");

switch (AutoUpdater.ReadyUpdate[x].Type)
{
case UpdateType.Panel:
DownloadFileWithProgress($"https://github.com/Killers0992/VrcOscIntegrations/releases/download/{AutoUpdater.ReadyUpdate[x].NewVersion}/VrcOscIntegrations.exe", AutoUpdater.ReadyUpdate[x].DisplayName, x + 1, updatesCount, tempPath, "VrcOscIntegrations.exe", progressBar, progressText);
DownloadFileWithProgress($"https://github.com/Killers0992/VrcOscIntegrations/releases/download/{AutoUpdater.ReadyUpdate[x].NewVersion}/VrcOscIntegrations.exe", AutoUpdater.ReadyUpdate[x].IsUpdate, AutoUpdater.ReadyUpdate[x].DisplayName, x + 1, updatesCount, targetPath, "VrcOscIntegrations.exe", progressBar, progressText);
break;
case UpdateType.Integration:
DownloadFileWithProgress($"{AutoUpdater.ReadyUpdate[x].GithubRepo}/releases/download/{AutoUpdater.ReadyUpdate[x].NewVersion}/{AutoUpdater.ReadyUpdate[x].IntegrationFileName}.dll", AutoUpdater.ReadyUpdate[x].DisplayName, x + 1, updatesCount, tempPath, $"{AutoUpdater.ReadyUpdate[x].IntegrationFileName}.dll", progressBar, progressText);
DownloadFileWithProgress($"{AutoUpdater.ReadyUpdate[x].GithubRepo}/releases/download/{AutoUpdater.ReadyUpdate[x].NewVersion}/{AutoUpdater.ReadyUpdate[x].IntegrationFileName}.dll", AutoUpdater.ReadyUpdate[x].IsUpdate, AutoUpdater.ReadyUpdate[x].DisplayName, x + 1, updatesCount, targetPath, $"{AutoUpdater.ReadyUpdate[x].IntegrationFileName}.dll", progressBar, progressText);

if (!string.IsNullOrEmpty(AutoUpdater.ReadyUpdate[x].DependenciesFileName))
{
var depFile = $"{AutoUpdater.ReadyUpdate[x].GithubRepo}/releases/download/{AutoUpdater.ReadyUpdate[x].NewVersion}/{AutoUpdater.ReadyUpdate[x].DependenciesFileName}.zip";
var depTargetFile = Path.Combine(Program.TempPath, $"{AutoUpdater.ReadyUpdate[x].DependenciesFileName}.zip");

DownloadFileWithProgress(depFile, AutoUpdater.ReadyUpdate[x].DisplayName + " deps", x + 1, updatesCount, depTargetFile, $"{AutoUpdater.ReadyUpdate[x].DependenciesFileName}.zip", progressBar, progressText, false);
DownloadFileWithProgress(depFile, AutoUpdater.ReadyUpdate[x].IsUpdate, AutoUpdater.ReadyUpdate[x].DisplayName + " deps", x + 1, updatesCount, depTargetFile, $"{AutoUpdater.ReadyUpdate[x].DependenciesFileName}.zip", progressBar, progressText, false);

Logger.Info("AutoUpdater", $"Extract all dependencies for {AutoUpdater.ReadyUpdate[x].DisplayName} into dependencies folder...", Color.White, Color.White);

Expand All @@ -339,12 +338,13 @@ private void fileDownloader_DoWork(object sender, System.ComponentModel.DoWorkEv
}
}

void DownloadFileWithProgress(string url, string displayName, int current, int max, string path, string fileName, PoisonProgressBar progress, PoisonLabel progressText, bool archive = true)
void DownloadFileWithProgress(string url, bool isUpdate, string displayName, int current, int max, string path, string fileName, PoisonProgressBar progress, PoisonLabel progressText, bool archive = true)
{
int bytesProcess = 0;
Stream remoteStream = null;
Stream localStream = null;
WebResponse response = null;
string tempPath = Path.Combine(Program.TempPath, fileName);

try
{
Expand All @@ -366,7 +366,7 @@ void DownloadFileWithProgress(string url, string displayName, int current, int m
{
remoteStream = response.GetResponseStream();

localStream = File.Create(path);
localStream = File.Create(tempPath);

byte[] buffer = new byte[1024];
int bytesRead = 0;
Expand Down Expand Up @@ -400,12 +400,12 @@ void DownloadFileWithProgress(string url, string displayName, int current, int m
{
progressText.Invoke(new Action(() =>
{
progressText.Text = $"Downloading update for {displayName}... ( {current}/{max} )";
progressText.Text = $"Downloading {(isUpdate ? "update for" : string.Empty)} {displayName}... ( {current}/{max} )";
}));
}
else
{
progressText.Text = $"Downloading update for {displayName}... ( {current}/{max} )";
progressText.Text = $"Downloading {(isUpdate ? "update for" : string.Empty)}... ( {current}/{max} )";
}
} while (bytesRead > 0);
}
Expand All @@ -422,12 +422,9 @@ void DownloadFileWithProgress(string url, string displayName, int current, int m
if (remoteStream != null) remoteStream.Close();
if (localStream != null) localStream.Close();

string currentPath = Path.Combine(Path.GetDirectoryName(path), fileName);

string archivePath = Path.Combine(Program.TempPath, $"old_{fileName}");

if (archive && File.Exists(currentPath)) File.Move(currentPath, archivePath, true);
File.Move(path, currentPath, true);
if (archive && File.Exists(path)) File.Move(path, archivePath, true);
File.Move(tempPath, path, true);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions VrcOscIntegrations/Models/PendingUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class PendingUpdate
{
public string Id { get; set; }
public bool IsUpdate { get; set; } = true;
public UpdateType Type { get; set; }
public string DisplayName { get; set; }
public string CurrentVersion { get; set; }
Expand Down
5 changes: 3 additions & 2 deletions version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"Version": "1.0.4",
"Version": "1.0.5",
"Changelogs": [
"- Move main directory to documents."
"- Fix again auto updater for integrations.",
"- Use new installer for integrations in browser."
]
}

0 comments on commit 0e0db06

Please sign in to comment.