From 974a8761ea1f199b72615b143effc5d1040869b1 Mon Sep 17 00:00:00 2001 From: Ravi Patel Date: Wed, 26 Aug 2020 11:18:23 +0530 Subject: [PATCH] Fixed an issue in ZipExtractor causing it to throw an error if file already exists. --- AutoUpdater.NET/AutoUpdater.NET.csproj | 7 ++- AutoUpdater.NET/AutoUpdater.cs | 61 ++++++++++----------- AutoUpdater.NET/NetworkAuthentication.cs | 1 + AutoUpdater.NET/Resources/ZipExtractor.exe | Bin 106496 -> 106496 bytes ZipExtractor/FormMain.cs | 6 +- ZipExtractor/ZipExtractor.csproj | 1 - 6 files changed, 40 insertions(+), 36 deletions(-) diff --git a/AutoUpdater.NET/AutoUpdater.NET.csproj b/AutoUpdater.NET/AutoUpdater.NET.csproj index e6b40ad8..9ac7a032 100644 --- a/AutoUpdater.NET/AutoUpdater.NET.csproj +++ b/AutoUpdater.NET/AutoUpdater.NET.csproj @@ -14,8 +14,6 @@ 1.6.1.0 true AutoUpdater.NET.snk - embedded - true en Autoupdater.NET.Official true @@ -28,9 +26,14 @@ autoupdate updater c# vb wpf winforms https://github.com/ravibpatel/AutoUpdater.NET/releases build + $(OutputPath)\$(Configuration)\AutoUpdater.NET.xml build\lib + pdbonly + + + full NETWPF diff --git a/AutoUpdater.NET/AutoUpdater.cs b/AutoUpdater.NET/AutoUpdater.cs index bf3bb67f..dc41ab87 100644 --- a/AutoUpdater.NET/AutoUpdater.cs +++ b/AutoUpdater.NET/AutoUpdater.cs @@ -506,48 +506,47 @@ private static void ShowError(Exception exception) } /// - /// Detects and exits all instances of running assembly, including current. + /// Detects and exits all instances of running assembly, including current. /// private static void Exit() { - if (ApplicationExitEvent != null) + var currentProcess = Process.GetCurrentProcess(); + foreach (var process in Process.GetProcessesByName(currentProcess.ProcessName)) { - ApplicationExitEvent(); - } - else - { - var currentProcess = Process.GetCurrentProcess(); - foreach (var process in Process.GetProcessesByName(currentProcess.ProcessName)) + string processPath; + try { - string processPath; - try - { - processPath = process.MainModule?.FileName; - } - catch (Win32Exception) + processPath = process.MainModule?.FileName; + } + catch (Win32Exception) + { + // Current process should be same as processes created by other instances of the application so it should be able to access modules of other instances. + // This means this is not the process we are looking for so we can safely skip this. + continue; + } + + //get all instances of assembly except current + if (process.Id != currentProcess.Id && currentProcess.MainModule?.FileName == processPath) + { + if (process.CloseMainWindow()) { - // Current process should be same as processes created by other instances of the application so it should be able to access modules of other instances. - // This means this is not the process we are looking for so we can safely skip this. - continue; + process.WaitForExit((int) TimeSpan.FromSeconds(10) + .TotalMilliseconds); //give some time to process message } - if (process.Id != currentProcess.Id && !string.IsNullOrEmpty(processPath) && - currentProcess.MainModule?.FileName == processPath - ) //get all instances of assembly except current + if (!process.HasExited) { - if (process.CloseMainWindow()) - { - process.WaitForExit((int) TimeSpan.FromSeconds(10) - .TotalMilliseconds); //give some time to process message - } - - if (!process.HasExited) - { - process.Kill(); //TODO show UI message asking user to close program himself instead of silently killing it - } + process.Kill(); //TODO show UI message asking user to close program himself instead of silently killing it } } - + } + + if (ApplicationExitEvent != null) + { + ApplicationExitEvent(); + } + else + { if (_isWinFormsApplication) { MethodInvoker methodInvoker = Application.Exit; diff --git a/AutoUpdater.NET/NetworkAuthentication.cs b/AutoUpdater.NET/NetworkAuthentication.cs index 1bf7f957..9a731e7c 100644 --- a/AutoUpdater.NET/NetworkAuthentication.cs +++ b/AutoUpdater.NET/NetworkAuthentication.cs @@ -23,6 +23,7 @@ public NetworkAuthentication(string username, string password) Password = password; } + /// public void Apply(ref MyWebClient webClient) { webClient.Credentials = new NetworkCredential(Username, Password); diff --git a/AutoUpdater.NET/Resources/ZipExtractor.exe b/AutoUpdater.NET/Resources/ZipExtractor.exe index e572304a4beee59cdafcf584f4bf843659d8f649..7ea4a4107e3a4b68dfe77866ead2177a0baee56b 100644 GIT binary patch delta 1057 zcmZwGTSydP6bJDCH#@UCJ2N}(%!ry=Y8Q8HTQBTprkR>uNywlZTG@jTRJsX^30t^} zVqyhuLk1DC4+dS9D5mK8AQD}u9wHy3d=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jhxto#3DyCjqBoK47*xsjET({X#(iG&tRYNT3mv{VyE?lu}*A3 zXS1W5#wsjF!PR$TgeB3p)XF}v1AH7w4A^qEFp1l?9$|>}Q&z~|S@YOiQAX25F^y_1 zs;I_LPjxODsn%gh{=$ac(*m!;8?WE#c(=CjxanBv*0+cGz`;)DF(R78N%>Q$&7%J^ p{nP&r&HU0?&cV!uicRD2FLN0e=+Tbc(~hto)m&vf-|}IC{RNXZ!+8Jz diff --git a/ZipExtractor/FormMain.cs b/ZipExtractor/FormMain.cs index 241ecf97..c924a672 100644 --- a/ZipExtractor/FormMain.cs +++ b/ZipExtractor/FormMain.cs @@ -95,6 +95,7 @@ private void FormMain_Shown(object sender, EventArgs e) try { + int progress = 0; for (var index = 0; index < entries.Count; index++) { if (_backgroundWorker.CancellationPending) @@ -110,6 +111,7 @@ private void FormMain_Shown(object sender, EventArgs e) #else string currentFile = string.Format(Resources.CurrentFileExtracting, entry.FilenameInZip); #endif + _backgroundWorker.ReportProgress(progress, currentFile); int retries = 0; bool notCopied = true; while (notCopied) @@ -117,7 +119,7 @@ private void FormMain_Shown(object sender, EventArgs e) try { #if NET45 - entry.ExtractToFile(Path.Combine(path, entry.FullName)); + entry.ExtractToFile(Path.Combine(path, entry.FullName), true); #else zip.ExtractFile(entry, Path.Combine(path, entry.FilenameInZip)); #endif @@ -144,7 +146,7 @@ private void FormMain_Shown(object sender, EventArgs e) } } - int progress = (index + 1) * 100 / entries.Count; + progress = (index + 1) * 100 / entries.Count; _backgroundWorker.ReportProgress(progress, currentFile); _logBuilder.AppendLine($"{currentFile} [{progress}%]"); diff --git a/ZipExtractor/ZipExtractor.csproj b/ZipExtractor/ZipExtractor.csproj index 82572694..1a0eee42 100644 --- a/ZipExtractor/ZipExtractor.csproj +++ b/ZipExtractor/ZipExtractor.csproj @@ -15,7 +15,6 @@ ZipExtractor.ico app.manifest true - ..\AutoUpdater.NET\Resources ZipExtractor.snk en none