From 4ece9636ccce9b6f1e8456d67428409a4f01dd03 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Sat, 17 May 2025 16:48:32 +0900 Subject: [PATCH 1/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f4ce2d1..78b7700 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ WelsonJS is tailored for developers who need a reliable, lightweight JavaScript ## Specifications * Built-in transpilers: [TypeScript](https://www.typescriptlang.org/), [Rescript](https://rescript-lang.org/), [CoffeeScript 2](https://coffeescript.org/), [LiveScript](https://livescript.net/) * **Ready to use on Windows machine immediately. No additional software installation is required.** -* **WelsonJS Launcher**: Manage instances (Like a container), User-defined variable editor, [Microsoft Monaco Editor](https://github.com/microsoft/monaco-editor) and [React](https://react.dev/) (Pre-embedded rich code editor), [Microsoft Copilot](https://copilot.microsoft.com), and [Azure AI Services](https://azure.microsoft.com/en-us/products/ai-services) on the code editor. +* **WelsonJS Launcher**: Manage instances (Like a container), User-defined variable editor, [Microsoft Monaco Editor](https://github.com/microsoft/monaco-editor) and [React](https://react.dev/) (Pre-embedded rich code editor), [Microsoft Copilot](https://copilot.microsoft.com), and [Azure AI Services](https://azure.microsoft.com/en-us/products/ai-services), Network tools (Whois, DNS Query, [Criminal IP CTI](https://www.criminalip.io/)) on the code editor. * ES5(ECMAScript 5), XML, JSON, YAML compatibility: [core-js](https://github.com/zloirock/core-js), [JSON2.js](https://github.com/douglascrockford/JSON-js), [js-yaml](https://github.com/nodeca/js-yaml) * HTML5 compatibility on the built-in HTML rendering engine: [html5shiv](https://github.com/aFarkas/html5shiv), [jquery-html5-placeholder-shim](https://github.com/parndt/jquery-html5-placeholder-shim), [Respond](https://github.com/scottjehl/Respond), [selectivizr](https://github.com/keithclark/selectivizr), [ExplorerCanvas](https://github.com/arv/ExplorerCanvas), [Modernizr](https://github.com/Modernizr/Modernizr) * Classical CSS Frameworks: [cascadeframework](https://github.com/jslegers/cascadeframework), [golden-layout](https://github.com/golden-layout/golden-layout) From a81ccc0efac09b8bca28c66f4f3a1471dc206557 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Wed, 21 May 2025 15:48:19 +0900 Subject: [PATCH 2/8] Improve `getElementPosition()` for handling elements within a shadow root --- lib/chrome.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/chrome.js b/lib/chrome.js index bf28f17..baeebc2 100644 --- a/lib/chrome.js +++ b/lib/chrome.js @@ -759,6 +759,31 @@ var ChromeObject = function() { } }; + this.getDeepElementPosition = function(selectors) { + var result = this.getEvaluatedValue('(function() { var rect = __getDocument().' + this.getShadowRootSelector(selectors) + '.getBoundingClientRect(); return [parseInt(rect.left), parseInt(rect.top), parseInt(__getWindow().pageXOffset + rect.left), parseInt(__getWindow().pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height)].join(","); })();'); + var pos = result.split(','); + + if (pos.length == 6) { + return { + "x": parseInt(pos[0]), + "y": parseInt(pos[1]), + "a": parseInt(pos[2]), + "b": parseInt(pos[3]), + "w": parseInt(pos[4]), + "h": parseInt(pos[5]) + }; + } else { + return { + "x": -1, + "y": -1, + "a": -1, + "b": -1, + "g": -1, + "d": -1 + }; + } + }; + this.getElementPositionByText = function(selector, searchText) { var result; var pos = -1; @@ -1423,7 +1448,7 @@ exports.startDebugInPrivate = function(url, proxy, profileName, debuggingPort, i ; }; -exports.VERSIONINFO = "Chrome Web Browser Debugging Interface (chrome.js) version 0.4.15"; +exports.VERSIONINFO = "Chrome Web Browser Debugging Interface (chrome.js) version 0.4.16"; exports.AUTHOR = "abuse@catswords.net"; exports.global = global; exports.require = global.require; From 8eb450c9d9588b2640b0e45824db3b9b57d063e0 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Wed, 21 May 2025 20:41:58 +0900 Subject: [PATCH 3/8] Fix `getDeepElementPosition()` couldn't get an element position --- lib/chrome.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chrome.js b/lib/chrome.js index baeebc2..f456a66 100644 --- a/lib/chrome.js +++ b/lib/chrome.js @@ -760,7 +760,7 @@ var ChromeObject = function() { }; this.getDeepElementPosition = function(selectors) { - var result = this.getEvaluatedValue('(function() { var rect = __getDocument().' + this.getShadowRootSelector(selectors) + '.getBoundingClientRect(); return [parseInt(rect.left), parseInt(rect.top), parseInt(__getWindow().pageXOffset + rect.left), parseInt(__getWindow().pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height)].join(","); })();'); + var result = this.getEvaluatedValue('(function() { var rect = __getDocument()' + this.getShadowRootSelector(selectors) + '.getBoundingClientRect(); return [parseInt(rect.left), parseInt(rect.top), parseInt(__getWindow().pageXOffset + rect.left), parseInt(__getWindow().pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height)].join(","); })();'); var pos = result.split(','); if (pos.length == 6) { From f2dc0a390424227cf4edf6a5be53037673905849 Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Thu, 22 May 2025 02:54:35 +0300 Subject: [PATCH 4/8] Revert "Merge pull request #257 from gnh1201/dev" This reverts commit 308fccf165b7b60ba6dfe17d1a979ceed513fd5b, reversing changes made to 26bc061819131abf840a48392bdb8cbd2e9aeba0. --- .../WelsonJS.Launcher/MainForm.cs | 4 -- .../WelsonJS.Launcher/ZipExtractor.cs | 72 +++++-------------- 2 files changed, 16 insertions(+), 60 deletions(-) diff --git a/WelsonJS.Toolkit/WelsonJS.Launcher/MainForm.cs b/WelsonJS.Toolkit/WelsonJS.Launcher/MainForm.cs index df444ce..d403103 100644 --- a/WelsonJS.Toolkit/WelsonJS.Launcher/MainForm.cs +++ b/WelsonJS.Toolkit/WelsonJS.Launcher/MainForm.cs @@ -144,10 +144,6 @@ namespace WelsonJS.Launcher // Run the application Program.RunCommandPrompt(workingDirectory, entryFileName, scriptName, cbUseSpecificScript.Checked, cbInteractiveServiceApp.Checked); } - else - { - MessageBox.Show("Failed to extract the ZIP file."); - } } catch (Exception ex) { diff --git a/WelsonJS.Toolkit/WelsonJS.Launcher/ZipExtractor.cs b/WelsonJS.Toolkit/WelsonJS.Launcher/ZipExtractor.cs index 7e86d64..01bab9a 100644 --- a/WelsonJS.Toolkit/WelsonJS.Launcher/ZipExtractor.cs +++ b/WelsonJS.Toolkit/WelsonJS.Launcher/ZipExtractor.cs @@ -5,7 +5,6 @@ using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Threading.Tasks; -using System.Windows.Forms; namespace WelsonJS.Launcher { @@ -17,14 +16,12 @@ namespace WelsonJS.Launcher public string FileName { get; set; } public string Path { get; set; } public Func ExtractCommand { get; set; } - public bool UseCmd { get; set; } = false; } private readonly List AvailableExtractors; public ZipExtractor() { - // Searches the computer for any known third-party ZIP utilities. AvailableExtractors = new List{ new Extractor { @@ -63,19 +60,6 @@ namespace WelsonJS.Launcher ExtractCommand = (src, dest) => $"x -o:\"{dest}\" \"{src}\" -y" }, new Extractor - { - Name = "IZArc", - FileName = "izarce.exe", - ExtractCommand = (src, dest) => $"-d -p\"{dest}\" \"{src}\"" - }, - new Extractor - { - Name = "jar (Java SDK)", - FileName = "jar.exe", - ExtractCommand = (src, dest) => $"xf \"{src}\"", - UseCmd = true - }, - new Extractor { Name = "tar (Windows)", // Windows 10 build 17063 or later FileName = "tar.exe", @@ -107,14 +91,14 @@ namespace WelsonJS.Launcher foreach (var extractor in AvailableExtractors.Where(e => e.Path != null)) { - if (RunProcess(extractor, filePath, workingDirectory, true)) + if (RunProcess(extractor.Path, extractor.ExtractCommand(filePath, workingDirectory))) return true; } - if (ExtractUsingPowerShell(filePath, workingDirectory, true)) + if (ExtractUsingPowerShell(filePath, workingDirectory)) return true; - if (ExtractUsingShell(filePath, workingDirectory, true)) + if (ExtractUsingShell(filePath, workingDirectory)) return true; return false; @@ -183,66 +167,42 @@ namespace WelsonJS.Launcher } } } - catch (Exception ex) - { - Trace.TraceInformation($"Ignored file or directory: {ex.Message}"); + catch { + // ignore an exception } } } - private bool RunProcess(string execFilePath, string arguments, string workingDirectory, bool useCmd = false, bool showConsole = false) + private bool RunProcess(string executableFilePath, string arguments) { - int exitCode = -1; - - string fileName = useCmd ? "cmd.exe" : execFilePath; - string adjustedArguments = useCmd ? $"/c \"{execFilePath}\" {arguments}" : arguments; - var psi = new ProcessStartInfo { - FileName = fileName, - Arguments = adjustedArguments, - WorkingDirectory = workingDirectory, - RedirectStandardOutput = !showConsole, - RedirectStandardError = !showConsole, - UseShellExecute = showConsole, - CreateNoWindow = !showConsole + FileName = executableFilePath, + Arguments = arguments, + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true }; using (var process = new Process { StartInfo = psi, EnableRaisingEvents = true }) { process.Start(); process.WaitForExit(); - exitCode = process.ExitCode; + return process.ExitCode == 0; } - - if (exitCode != 0) - Trace.TraceWarning($"{fileName} exit with code {exitCode}"); - else - Trace.TraceInformation($"{fileName} finished successfully"); - - return exitCode == 0; } - private bool RunProcess(Extractor extractor, string filePath, string workingDirectory, bool showConsole = false) - { - return RunProcess(extractor.Path, - extractor.ExtractCommand(filePath, workingDirectory), - workingDirectory, - extractor.UseCmd, - showConsole - ); - } - - private bool ExtractUsingPowerShell(string filePath, string workingDirectory, bool showConsole = false) + private bool ExtractUsingPowerShell(string filePath, string workingDirectory) { var escapedSrc = filePath.Replace("'", "''"); var escapedDest = workingDirectory.Replace("'", "''"); var script = $"Expand-Archive -LiteralPath '{escapedSrc}' -DestinationPath '{escapedDest}' -Force"; - return RunProcess("powershell.exe", $"-NoProfile -Command \"{script}\"", workingDirectory); + return RunProcess("powershell.exe", $"-NoProfile -Command \"{script}\""); } - private bool ExtractUsingShell(string filePath, string workingDirectory, bool showConsole = false) + private bool ExtractUsingShell(string filePath, string workingDirectory) { var shellAppType = Type.GetTypeFromProgID("Shell.Application"); if (shellAppType == null) From ea3e70ab24abc7cdb73fb723878da49f75b5cb8a Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Thu, 22 May 2025 02:54:47 +0300 Subject: [PATCH 5/8] Revert "Merge pull request #256 from gnh1201/dev" This reverts commit 26bc061819131abf840a48392bdb8cbd2e9aeba0, reversing changes made to 4d37a3eb4a1b741a2f72747983aaa0816693b1e7. --- .../WelsonJS.Launcher/ZipExtractor.cs | 41 +++++-------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/WelsonJS.Toolkit/WelsonJS.Launcher/ZipExtractor.cs b/WelsonJS.Toolkit/WelsonJS.Launcher/ZipExtractor.cs index 01bab9a..2a838bb 100644 --- a/WelsonJS.Toolkit/WelsonJS.Launcher/ZipExtractor.cs +++ b/WelsonJS.Toolkit/WelsonJS.Launcher/ZipExtractor.cs @@ -42,6 +42,12 @@ namespace WelsonJS.Launcher ExtractCommand = (src, dest) => $"-ext2simple \"{src}\" \"{dest}\"" }, new Extractor + { + Name = "tar (Windows)", + FileName = "tar.exe", + ExtractCommand = (src, dest) => $"-xf \"{src}\" -C \"{dest}\"" + }, + new Extractor { Name = "WinZip", FileName = "wzunzip.exe", @@ -58,18 +64,6 @@ namespace WelsonJS.Launcher Name = "Bandizip", FileName = "Bandizip.exe", ExtractCommand = (src, dest) => $"x -o:\"{dest}\" \"{src}\" -y" - }, - new Extractor - { - Name = "tar (Windows)", // Windows 10 build 17063 or later - FileName = "tar.exe", - ExtractCommand = (src, dest) => $"-xf \"{src}\" -C \"{dest}\"" - }, - new Extractor - { - Name = "unzip", // Info-ZIP, Cygwin - FileName = "unzip.exe", - ExtractCommand = (src, dest) => $"\"{src}\" -d \"{dest}\" -o" } }; @@ -92,16 +86,12 @@ namespace WelsonJS.Launcher foreach (var extractor in AvailableExtractors.Where(e => e.Path != null)) { if (RunProcess(extractor.Path, extractor.ExtractCommand(filePath, workingDirectory))) + { return true; + } } - if (ExtractUsingPowerShell(filePath, workingDirectory)) - return true; - - if (ExtractUsingShell(filePath, workingDirectory)) - return true; - - return false; + return ExtractUsingShell(filePath, workingDirectory); } private bool IsValidFile(string filePath) @@ -167,9 +157,7 @@ namespace WelsonJS.Launcher } } } - catch { - // ignore an exception - } + catch { } } } @@ -193,15 +181,6 @@ namespace WelsonJS.Launcher } } - private bool ExtractUsingPowerShell(string filePath, string workingDirectory) - { - var escapedSrc = filePath.Replace("'", "''"); - var escapedDest = workingDirectory.Replace("'", "''"); - var script = $"Expand-Archive -LiteralPath '{escapedSrc}' -DestinationPath '{escapedDest}' -Force"; - - return RunProcess("powershell.exe", $"-NoProfile -Command \"{script}\""); - } - private bool ExtractUsingShell(string filePath, string workingDirectory) { var shellAppType = Type.GetTypeFromProgID("Shell.Application"); From 4d9427f514c7bded83913d5a02187cb4ccae9f39 Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Thu, 22 May 2025 02:54:55 +0300 Subject: [PATCH 6/8] Revert "Merge pull request #255 from gnh1201/dev" This reverts commit 4d37a3eb4a1b741a2f72747983aaa0816693b1e7, reversing changes made to fc31b528daa944f48a6cc409695a55eddb3f0ffa. --- .../WelsonJS.Launcher/MainForm.cs | 25 +- .../WelsonJS.Launcher.csproj | 9 +- .../WelsonJS.Launcher/ZipExtractor.cs | 214 ------------------ .../WelsonJS.Launcher/packages.config | 4 + 4 files changed, 22 insertions(+), 230 deletions(-) delete mode 100644 WelsonJS.Toolkit/WelsonJS.Launcher/ZipExtractor.cs create mode 100644 WelsonJS.Toolkit/WelsonJS.Launcher/packages.config diff --git a/WelsonJS.Toolkit/WelsonJS.Launcher/MainForm.cs b/WelsonJS.Toolkit/WelsonJS.Launcher/MainForm.cs index d403103..dcb3ce2 100644 --- a/WelsonJS.Toolkit/WelsonJS.Launcher/MainForm.cs +++ b/WelsonJS.Toolkit/WelsonJS.Launcher/MainForm.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.IO; +using System.IO.Compression; using System.Security.Principal; using System.Threading.Tasks; using System.Windows.Forms; @@ -11,14 +12,11 @@ namespace WelsonJS.Launcher { private string workingDirectory; private string instanceId; - private readonly string entryFileName; + private string entryFileName; private string scriptName; - private readonly ZipExtractor zipExtractor; public MainForm() { - zipExtractor = new ZipExtractor(); - entryFileName = "bootstrap.bat"; InitializeComponent(); @@ -132,18 +130,17 @@ namespace WelsonJS.Launcher Directory.Delete(workingDirectory, true); } - // try to extact ZIP compressed file - if (zipExtractor.Extract(filePath, workingDirectory)) - { - // record the first deploy time - RecordFirstDeployTime(workingDirectory); + // try to extact ZIP file + ZipFile.ExtractToDirectory(filePath, workingDirectory); - // follow the sub-directory - workingDirectory = Program.GetWorkingDirectory(instanceId, true); + // record the first deploy time + RecordFirstDeployTime(workingDirectory); - // Run the application - Program.RunCommandPrompt(workingDirectory, entryFileName, scriptName, cbUseSpecificScript.Checked, cbInteractiveServiceApp.Checked); - } + // follow the sub-directory + workingDirectory = Program.GetWorkingDirectory(instanceId, true); + + // Run the appliction + Program.RunCommandPrompt(workingDirectory, entryFileName, scriptName, cbUseSpecificScript.Checked, cbInteractiveServiceApp.Checked); } catch (Exception ex) { diff --git a/WelsonJS.Toolkit/WelsonJS.Launcher/WelsonJS.Launcher.csproj b/WelsonJS.Toolkit/WelsonJS.Launcher/WelsonJS.Launcher.csproj index 7f2c096..1131013 100644 --- a/WelsonJS.Toolkit/WelsonJS.Launcher/WelsonJS.Launcher.csproj +++ b/WelsonJS.Toolkit/WelsonJS.Launcher/WelsonJS.Launcher.csproj @@ -56,12 +56,17 @@ favicon.ico - + + + ..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll + True + True + @@ -103,7 +108,6 @@ GlobalSettingsForm.cs - EnvForm.cs @@ -122,6 +126,7 @@ GlobalSettingsForm.cs + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/WelsonJS.Toolkit/WelsonJS.Launcher/ZipExtractor.cs b/WelsonJS.Toolkit/WelsonJS.Launcher/ZipExtractor.cs deleted file mode 100644 index 2a838bb..0000000 --- a/WelsonJS.Toolkit/WelsonJS.Launcher/ZipExtractor.cs +++ /dev/null @@ -1,214 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using System.Threading.Tasks; - -namespace WelsonJS.Launcher -{ - public class ZipExtractor - { - class Extractor - { - public string Name { get; set; } - public string FileName { get; set; } - public string Path { get; set; } - public Func ExtractCommand { get; set; } - } - - private readonly List AvailableExtractors; - - public ZipExtractor() - { - AvailableExtractors = new List{ - new Extractor - { - Name = "7z", - FileName = "7z.exe", - ExtractCommand = (src, dest) => $"x \"{src}\" -o\"{dest}\" -y" - }, - new Extractor - { - Name = "WinRAR", - FileName = "rar.exe", - ExtractCommand = (src, dest) => $"x -o+ \"{src}\" \"{dest}\\\"" - }, - new Extractor - { - Name = "PeaZip", - FileName = "peazip.exe", - ExtractCommand = (src, dest) => $"-ext2simple \"{src}\" \"{dest}\"" - }, - new Extractor - { - Name = "tar (Windows)", - FileName = "tar.exe", - ExtractCommand = (src, dest) => $"-xf \"{src}\" -C \"{dest}\"" - }, - new Extractor - { - Name = "WinZip", - FileName = "wzunzip.exe", - ExtractCommand = (src, dest) => $"-d \"{dest}\" \"{src}\"" - }, - new Extractor - { - Name = "ALZip", - FileName = "ALZipcon.exe", - ExtractCommand = (src, dest) => $"-x \"{src}\" \"{dest}\"" - }, - new Extractor - { - Name = "Bandizip", - FileName = "Bandizip.exe", - ExtractCommand = (src, dest) => $"x -o:\"{dest}\" \"{src}\" -y" - } - }; - - Task.Run(() => CheckAvailableExtractors()); - } - - public bool Extract(string filePath, string workingDirectory) - { - if (!File.Exists(filePath)) - throw new FileNotFoundException("The specified file does not exist.", filePath); - - if (!filePath.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)) - throw new ArgumentException("The specified file is not a ZIP archive."); - - if (!IsValidFile(filePath)) - throw new InvalidDataException("The specified file is not a valid ZIP archive."); - - Directory.CreateDirectory(workingDirectory); - - foreach (var extractor in AvailableExtractors.Where(e => e.Path != null)) - { - if (RunProcess(extractor.Path, extractor.ExtractCommand(filePath, workingDirectory))) - { - return true; - } - } - - return ExtractUsingShell(filePath, workingDirectory); - } - - private bool IsValidFile(string filePath) - { - byte[] signature = new byte[4]; - - using (var fs = File.OpenRead(filePath)) - { - if (fs.Length < 4) - return false; - - int bytesRead = fs.Read(signature, 0, 4); - if (bytesRead < 4) - return false; - } - - return signature.SequenceEqual(new byte[] { 0x50, 0x4B, 0x03, 0x04 }); - } - - private void CheckAvailableExtractors() - { - var fileNames = AvailableExtractors.Select(e => e.FileName).ToList(); - - // Check PATH environment variable - var paths = (Environment.GetEnvironmentVariable("PATH") ?? "").Split(Path.PathSeparator); - foreach (var dir in paths) - { - foreach (var fileName in fileNames) - { - var path = Path.Combine(dir.Trim(), fileName); - if (File.Exists(path)) - { - var index = fileNames.IndexOf(fileName); - var extractor = AvailableExtractors[index]; - extractor.Path = path; - } - } - } - - // Check common install locations - var programDirs = new[] - { - Path.Combine(Program.GetAppDataPath(), "bin"), // find an extractor from APPDATA directory - Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), - Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) - }; - - foreach (var rootDir in programDirs) - { - if (!Directory.Exists(rootDir)) - continue; - - try - { - foreach (var file in Directory.EnumerateFiles(rootDir, "*", SearchOption.AllDirectories)) - { - var fileName = Path.GetFileName(file); - if (fileNames.Contains(fileName)) - { - var index = fileNames.IndexOf(fileName); - var extractor = AvailableExtractors[index]; - extractor.Path = file; - } - } - } - catch { } - } - } - - private bool RunProcess(string executableFilePath, string arguments) - { - var psi = new ProcessStartInfo - { - FileName = executableFilePath, - Arguments = arguments, - RedirectStandardOutput = true, - RedirectStandardError = true, - UseShellExecute = false, - CreateNoWindow = true - }; - - using (var process = new Process { StartInfo = psi, EnableRaisingEvents = true }) - { - process.Start(); - process.WaitForExit(); - return process.ExitCode == 0; - } - } - - private bool ExtractUsingShell(string filePath, string workingDirectory) - { - var shellAppType = Type.GetTypeFromProgID("Shell.Application"); - if (shellAppType == null) - return false; - - dynamic shell = Activator.CreateInstance(shellAppType); - if (shell == null) - return false; - - dynamic zip = shell.NameSpace(filePath); - dynamic dest = shell.NameSpace(workingDirectory); - if (zip == null || dest == null) - return false; - - int expected = zip.Items().Count; - dest.CopyHere(zip.Items(), 16); - - // wait (max 30 s) until all files appear - var sw = Stopwatch.StartNew(); - while (dest.Items().Count < expected && sw.Elapsed < TimeSpan.FromSeconds(30)) - System.Threading.Thread.Sleep(200); - - Marshal.ReleaseComObject(zip); - Marshal.ReleaseComObject(dest); - Marshal.ReleaseComObject(shell); - - return dest.Items().Count == expected; - } - } -} diff --git a/WelsonJS.Toolkit/WelsonJS.Launcher/packages.config b/WelsonJS.Toolkit/WelsonJS.Launcher/packages.config new file mode 100644 index 0000000..888dd5e --- /dev/null +++ b/WelsonJS.Toolkit/WelsonJS.Launcher/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From e74b7b8b7311828bb7e3395c28c9f09565eb04fe Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Thu, 22 May 2025 03:00:34 +0300 Subject: [PATCH 7/8] Remove dependency to `System.IO.Compression.ZipFile` package. --- .../WelsonJS.Launcher/WelsonJS.Launcher.csproj | 8 +------- WelsonJS.Toolkit/WelsonJS.Launcher/packages.config | 4 ---- 2 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 WelsonJS.Toolkit/WelsonJS.Launcher/packages.config diff --git a/WelsonJS.Toolkit/WelsonJS.Launcher/WelsonJS.Launcher.csproj b/WelsonJS.Toolkit/WelsonJS.Launcher/WelsonJS.Launcher.csproj index 1131013..161757e 100644 --- a/WelsonJS.Toolkit/WelsonJS.Launcher/WelsonJS.Launcher.csproj +++ b/WelsonJS.Toolkit/WelsonJS.Launcher/WelsonJS.Launcher.csproj @@ -1,4 +1,4 @@ - + @@ -62,11 +62,6 @@ - - ..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll - True - True - @@ -126,7 +121,6 @@ GlobalSettingsForm.cs - SettingsSingleFileGenerator Settings.Designer.cs diff --git a/WelsonJS.Toolkit/WelsonJS.Launcher/packages.config b/WelsonJS.Toolkit/WelsonJS.Launcher/packages.config deleted file mode 100644 index 888dd5e..0000000 --- a/WelsonJS.Toolkit/WelsonJS.Launcher/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file From d214a8d7493d945638c7cf636274e6d501bf4316 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Sat, 24 May 2025 12:16:11 +0900 Subject: [PATCH 8/8] Fix issues and PR #254 #260 --- .../WelsonJS.Launcher/MainForm.cs | 67 +++++++++---------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/WelsonJS.Toolkit/WelsonJS.Launcher/MainForm.cs b/WelsonJS.Toolkit/WelsonJS.Launcher/MainForm.cs index dcb3ce2..142fb90 100644 --- a/WelsonJS.Toolkit/WelsonJS.Launcher/MainForm.cs +++ b/WelsonJS.Toolkit/WelsonJS.Launcher/MainForm.cs @@ -12,7 +12,7 @@ namespace WelsonJS.Launcher { private string workingDirectory; private string instanceId; - private string entryFileName; + private readonly string entryFileName; private string scriptName; public MainForm() @@ -23,7 +23,7 @@ namespace WelsonJS.Launcher if (IsInAdministrator()) { - Text = Text + " (Administrator)"; + Text += " (Administrator)"; } notifyIcon1.DoubleClick += OnShow; @@ -109,8 +109,10 @@ namespace WelsonJS.Launcher if (openFileDialog.ShowDialog() == DialogResult.OK) { string filePath = openFileDialog.FileName; - ExtractAndRun(filePath); + Task.Run(() => ExtractAndRun(filePath)); } + + DisableUI(); } } @@ -120,43 +122,33 @@ namespace WelsonJS.Launcher workingDirectory = Program.GetWorkingDirectory(instanceId); scriptName = txtUseSpecificScript.Text; - Task.Run(() => + try { - try + // try to validate GUID + if (Directory.Exists(workingDirectory)) { - // If exists, delete all - if (Directory.Exists(workingDirectory)) - { - Directory.Delete(workingDirectory, true); - } - - // try to extact ZIP file - ZipFile.ExtractToDirectory(filePath, workingDirectory); - - // record the first deploy time - RecordFirstDeployTime(workingDirectory); - - // follow the sub-directory - workingDirectory = Program.GetWorkingDirectory(instanceId, true); - - // Run the appliction - Program.RunCommandPrompt(workingDirectory, entryFileName, scriptName, cbUseSpecificScript.Checked, cbInteractiveServiceApp.Checked); - } - catch (Exception ex) - { - SafeInvoke(() => - { - MessageBox.Show("Error: " + ex.Message); - }); + throw new InvalidOperationException("GUID validation failed. Directory already exists."); } - // Enable UI - SafeInvoke(() => { - EnableUI(); - }); - }); + // try to extract ZIP file + ZipFile.ExtractToDirectory(filePath, workingDirectory); - DisableUI(); + // record the first deploy time + RecordFirstDeployTime(workingDirectory); + + // follow the sub-directory + workingDirectory = Program.GetWorkingDirectory(instanceId, true); + + // Run the appliction + Program.RunCommandPrompt(workingDirectory, entryFileName, scriptName, cbUseSpecificScript.Checked, cbInteractiveServiceApp.Checked); + } + catch (Exception ex) + { + SafeInvoke(() => MessageBox.Show($"Extraction failed: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)); + } + + // Enable UI + SafeInvoke(() => EnableUI()); } private void RecordFirstDeployTime(string directory) @@ -181,8 +173,9 @@ namespace WelsonJS.Launcher WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent()); return wp.IsInRole(WindowsBuiltInRole.Administrator); } - catch + catch (Exception ex) { + Trace.TraceInformation($"The current user is not an administrator, or the check failed: {ex.Message}"); return false; } } @@ -226,7 +219,7 @@ namespace WelsonJS.Launcher } catch (Exception ex) { - MessageBox.Show("Failed to run as administrator: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"Failed to run as Administrator: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else