Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions Views/DownloadProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@

namespace FallGuysStats {
public partial class DownloadProgress : MetroFramework.Forms.MetroForm {
public string CurrentExeName { get; set; }
public ZipWebClient ZipWebClient { get; set; }
public string FileName { get; set; }
public string ZipFileName { get; set; }
public string DownloadUrl { get; set; }

public DownloadProgress() {
this.InitializeComponent();
}

private void Progress_Load(object sender, EventArgs e) {
this.SetTheme(Stats.CurrentTheme);
this.ChangeLanguage();
this.DownloadNewVersion();
}

private void SetTheme(MetroThemeStyle theme) {
this.Theme = theme;
this.lblDownloadDescription.ForeColor = theme == MetroThemeStyle.Light ? Color.Black : Color.DarkGray;
Expand All @@ -35,33 +36,37 @@ private void zipWebClient_DownloadProgressChanged(object sender, DownloadProgres
this.mpbProgressBar.Invalidate();
}
}

private void zipWebClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) {
this.lblDownloadDescription.Text = Multilingual.GetWord("main_update_complete");
this.lblDownloadDescription.Refresh();
string exeName = null;
using (ZipArchive zipFile = new ZipArchive(new FileStream(this.FileName, FileMode.Open), ZipArchiveMode.Read)) {
using (ZipArchive zipFile = new ZipArchive(new FileStream(this.ZipFileName, FileMode.Open), ZipArchiveMode.Read)) {
foreach (var entry in zipFile.Entries) {
if (entry.Name.IndexOf(".exe", StringComparison.OrdinalIgnoreCase) > 0) {
exeName = entry.Name;
}
if (File.Exists($"{Stats.CURRENTDIR}{entry.Name}")) {
File.Move($"{Stats.CURRENTDIR}{entry.Name}", $"{Stats.CURRENTDIR}{entry.Name}.bak");
}
entry.ExtractToFile($"{Stats.CURRENTDIR}{entry.Name}", true);
if (entry.Name.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) {
if (!File.Exists($"{Stats.CURRENTDIR}{this.CurrentExeName}.bak")) {
File.Move($"{Stats.CURRENTDIR}{this.CurrentExeName}", $"{Stats.CURRENTDIR}{this.CurrentExeName}.bak");
}
entry.ExtractToFile($"{Stats.CURRENTDIR}{this.CurrentExeName}", true);
} else {
entry.ExtractToFile($"{Stats.CURRENTDIR}{entry.Name}", true);
}
}
}
File.Delete(this.FileName);
Process.Start(new ProcessStartInfo($"{Stats.CURRENTDIR}{exeName}"));
File.Delete(this.ZipFileName);
Process.Start(new ProcessStartInfo($"{Stats.CURRENTDIR}{this.CurrentExeName}"));
Process.GetCurrentProcess().Kill();
}

private void DownloadNewVersion() {
this.lblDownloadDescription.Text = Multilingual.GetWord("main_updating_program");
this.ZipWebClient.DownloadProgressChanged += this.zipWebClient_DownloadProgressChanged;
this.ZipWebClient.DownloadFileCompleted += this.zipWebClient_DownloadFileCompleted;
this.ZipWebClient.DownloadFileAsync(new Uri(this.DownloadUrl), this.FileName);
this.ZipWebClient.DownloadFileAsync(new Uri(this.DownloadUrl), this.ZipFileName);
}

private void ChangeLanguage() {
this.lblDownloadDescription.Text = Multilingual.GetWord("main_update_program");
this.lblDownloadDescription.Font = Overlay.GetDefaultFont(18, Stats.CurrentLanguage);
Expand Down
20 changes: 10 additions & 10 deletions Views/LevelDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ private void DeleteShow() {
this.preventPaging = true;
lock (this.StatsForm.StatsDB) {
Task.Run(() => {
Task dbTaskDeleteShow = new Task(() => {
Task deleteShowTask = new Task(() => {
this.StatsForm.StatsDB.BeginTrans();
foreach (DataGridViewRow row in this.gridDetails.SelectedRows) {
RoundInfo bi = row.DataBoundItem as RoundInfo;
Expand All @@ -1067,7 +1067,7 @@ private void DeleteShow() {
}
this.StatsForm.StatsDB.Commit();
});
this.StatsForm.AddToDbTasksList(dbTaskDeleteShow, false);
this.StatsForm.RunDatabaseTask(deleteShowTask, false);
}).ContinueWith(prevTask => {
this.BeginInvoke((MethodInvoker)delegate {
this.RoundDetails = this.StatsForm.GetShowsForDisplay();
Expand Down Expand Up @@ -1108,7 +1108,7 @@ private void moveShows_Click(object sender, EventArgs e) {
int toProfileId = moveShows.SelectedProfileId;
lock (this.StatsForm.StatsDB) {
Task.Run(() => {
Task dbTaskMoveShows = new Task(() => {
Task moveShowsTask = new Task(() => {
this.StatsForm.StatsDB.BeginTrans();
foreach (DataGridViewRow row in this.gridDetails.SelectedRows) {
RoundInfo bi = row.DataBoundItem as RoundInfo;
Expand All @@ -1120,7 +1120,7 @@ private void moveShows_Click(object sender, EventArgs e) {
}
this.StatsForm.StatsDB.Commit();
});
this.StatsForm.AddToDbTasksList(dbTaskMoveShows, false);
this.StatsForm.RunDatabaseTask(moveShowsTask, false);
}).ContinueWith(prevTask => {
this.BeginInvoke((MethodInvoker)delegate {
this.RoundDetails = this.StatsForm.GetShowsForDisplay();
Expand Down Expand Up @@ -1158,7 +1158,7 @@ private void deleteFinishTime_Click(object sender, EventArgs e) {
this.preventPaging = true;
lock (this.StatsForm.StatsDB) {
Task.Run(() => {
Task dbTaskDeleteFinishTime = new Task(() => {
Task deleteFinishTimeTask = new Task(() => {
this.StatsForm.StatsDB.BeginTrans();
PersonalBestLog pbLog = this.StatsForm.PersonalBestLogCache.Find(l => l.PbDate == ri.Finish);
if (pbLog != null) {
Expand All @@ -1174,7 +1174,7 @@ private void deleteFinishTime_Click(object sender, EventArgs e) {
this.StatsForm.RoundDetails.Update(ri);
this.StatsForm.StatsDB.Commit();
});
this.StatsForm.AddToDbTasksList(dbTaskDeleteFinishTime, false);
this.StatsForm.RunDatabaseTask(deleteFinishTimeTask, false);
}).ContinueWith(prevTask => {
this.BeginInvoke((MethodInvoker)delegate {
this.spinnerTransition.Stop();
Expand Down Expand Up @@ -1250,12 +1250,12 @@ private void updateLevel_Click(object sender, EventArgs e) {
}

lock (this.StatsForm.StatsDB) {
Task dbTaskUpdateCreativeLevel = new Task(() => {
Task updateCreativeLevelTask = new Task(() => {
this.StatsForm.StatsDB.BeginTrans();
this.StatsForm.RoundDetails.Update(filteredInfo);
this.StatsForm.StatsDB.Commit();
});
this.StatsForm.AddToDbTasksList(dbTaskUpdateCreativeLevel, false);
this.StatsForm.RunDatabaseTask(updateCreativeLevelTask, false);
}

this.StatsForm.UpdateCreativeLevel(ri.Name, shareCode, snapshot);
Expand Down Expand Up @@ -1302,12 +1302,12 @@ private void updateLevel_Click(object sender, EventArgs e) {
}

lock (this.StatsForm.StatsDB) {
Task dbTaskUpdateCreativeLevel = new Task(() => {
Task updateCreativeLevelTask = new Task(() => {
this.StatsForm.StatsDB.BeginTrans();
this.StatsForm.RoundDetails.Update(filteredInfo);
this.StatsForm.StatsDB.Commit();
});
this.StatsForm.AddToDbTasksList(dbTaskUpdateCreativeLevel, false);
this.StatsForm.RunDatabaseTask(updateCreativeLevelTask, false);
}

this.StatsForm.UpdateCreativeLevel(ri.Name, shareCode, levelData);
Expand Down
2 changes: 1 addition & 1 deletion Views/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ private void ChangeTab(object sender, EventArgs e) {
this.panelFallGuys.Visible = true;
} else if (sender.Equals(this.tileAbout)) {
this.tileAbout.Style = MetroColorStyle.Teal;
#if AllowUpdate
#if AllowUpdate
this.lblupdateNote.Text = Multilingual.GetWord("settings_checking_for_updates");
using (ZipWebClient web = new ZipWebClient()) {
string assemblyInfo = web.DownloadString(@"https://raw.githubusercontent.com/ShootMe/FallGuysStats/master/Properties/AssemblyInfo.cs");
Expand Down
Loading