private void ProcessCmdArgs() { // Commandline Arguments. Command Line Arguments. if (cmdParser.Contains("autoconnect")) { isAutoConnectCmd = true; } if (cmdParser.Contains("file")) { String [] FilePathStringArray = cmdParser.Arguments["file"][0].Split(','); if (FilePathStringArray.Length > 0) { foreach (String FilePath in FilePathStringArray) { String temporary = richText_Playlist.Text; AppendItemToPlaylist(FilePath, ref temporary); richText_Playlist.Text = temporary; } IsFilePathGiven = true; } } if (cmdParser.Contains("exit")) { isImmediateExitCmd = true; } }
private void ProcessCmdArgs() { // Commandline Arguments. Command Line Arguments. if (cmdParser.Contains("autoconnect")) { isAutoConnectCmd = true; } if (cmdParser.Contains("autoplay")) { isAutoPlayCmd = true; } }
public Task <bool> ExecuteAsync() { return(Task.Run(() => { Console.WriteLine("Build Electron Application..."); SimpleCommandLineParser parser = new SimpleCommandLineParser(); parser.Parse(_args); //This version will be shared between the dotnet publish and electron-builder commands string version = null; if (parser.Arguments.ContainsKey(_paramVersion)) { version = parser.Arguments[_paramVersion][0]; } if (!parser.Arguments.ContainsKey(_paramTarget) || parser.Arguments[_paramTarget].Length == 0) { Console.WriteLine($"Error: missing '{_paramTarget}' argument."); Console.WriteLine(COMMAND_ARGUMENTS); return false; } var desiredPlatform = parser.Arguments[_paramTarget][0]; string specifiedFromCustom = string.Empty; if (desiredPlatform == "custom" && parser.Arguments[_paramTarget].Length > 1) { specifiedFromCustom = parser.Arguments[_paramTarget][1]; } string configuration = "Release"; if (parser.Arguments.ContainsKey(_paramDotNetConfig)) { configuration = parser.Arguments[_paramDotNetConfig][0]; } var platformInfo = GetTargetPlatformInformation.Do(desiredPlatform, specifiedFromCustom); Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid}..."); string tempPath = Path.Combine(Directory.GetCurrentDirectory(), "obj", "desktop", desiredPlatform); if (Directory.Exists(tempPath) == false) { Directory.CreateDirectory(tempPath); } else { Directory.Delete(tempPath, true); Directory.CreateDirectory(tempPath); } Console.WriteLine("Executing dotnet publish in this directory: " + tempPath); string tempBinPath = Path.Combine(tempPath, "bin"); Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid} under {configuration}-Configuration..."); var dotNetPublishFlags = GetDotNetPublishFlags(parser); var command = $"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {string.Join(' ', dotNetPublishFlags.Select(kvp => $"{kvp.Key}={kvp.Value}"))} --self-contained"; // output the command Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(command); Console.ResetColor(); var resultCode = ProcessHelper.CmdExecute(command, Directory.GetCurrentDirectory()); if (resultCode != 0) { Console.WriteLine("Error occurred during dotnet publish: " + resultCode); return false; } DeployEmbeddedElectronFiles.Do(tempPath); var nodeModulesDirPath = Path.Combine(tempPath, "node_modules"); if (parser.Arguments.ContainsKey(_paramPackageJson)) { Console.WriteLine("Copying custom package.json."); File.Copy(parser.Arguments[_paramPackageJson][0], Path.Combine(tempPath, "package.json"), true); } var checkForNodeModulesDirPath = Path.Combine(tempPath, "node_modules"); if (Directory.Exists(checkForNodeModulesDirPath) == false || parser.Contains(_paramForceNodeInstall) || parser.Contains(_paramPackageJson)) { Console.WriteLine("Start npm install..."); } ProcessHelper.CmdExecute("npm install --production", tempPath); Console.WriteLine("ElectronHostHook handling started..."); string electronhosthookDir = Path.Combine(Directory.GetCurrentDirectory(), "ElectronHostHook"); if (Directory.Exists(electronhosthookDir)) { string hosthookDir = Path.Combine(tempPath, "ElectronHostHook"); DirectoryCopy.Do(electronhosthookDir, hosthookDir, true, new List <string>() { "node_modules" }); Console.WriteLine("Start npm install for hosthooks..."); ProcessHelper.CmdExecute("npm install", hosthookDir); // ToDo: Not sure if this runs under linux/macos ProcessHelper.CmdExecute(@"npx tsc -p . --sourceMap false", hosthookDir); } Console.WriteLine("Build Electron Desktop Application..."); // Specifying an absolute path supercedes a relative path string buildPath = Path.Combine(Directory.GetCurrentDirectory(), "bin", "desktop"); if (parser.Arguments.ContainsKey(_paramAbsoluteOutput)) { buildPath = parser.Arguments[_paramAbsoluteOutput][0]; } else if (parser.Arguments.ContainsKey(_paramOutputDirectory)) { buildPath = Path.Combine(Directory.GetCurrentDirectory(), parser.Arguments[_paramOutputDirectory][0]); } Console.WriteLine("Executing electron magic in this directory: " + buildPath); string electronArch = "x64"; if (parser.Arguments.ContainsKey(_paramElectronArch)) { electronArch = parser.Arguments[_paramElectronArch][0]; } string electronParams = ""; if (parser.Arguments.ContainsKey(_paramElectronParams)) { electronParams = parser.Arguments[_paramElectronParams][0]; } // ToDo: Make the same thing easer with native c# - we can save a tmp file in production code :) Console.WriteLine("Create electron-builder configuration file..."); string manifestFileName = "electron.manifest.json"; if (parser.Arguments.ContainsKey(_manifest)) { manifestFileName = parser.Arguments[_manifest].First(); } ProcessHelper.CmdExecute( string.IsNullOrWhiteSpace(version) ? $"node build-helper.js {manifestFileName}" : $"node build-helper.js {manifestFileName} {version}", tempPath); Console.WriteLine($"Package Electron App for Platform {platformInfo.ElectronPackerPlatform}..."); ProcessHelper.CmdExecute($"npx electron-builder --config=./bin/electron-builder.json --{platformInfo.ElectronPackerPlatform} --{electronArch} -c.electronVersion=13.1.5 {electronParams}", tempPath); Console.WriteLine("... done"); return true; })); }
public Task <bool> ExecuteAsync() { return(Task.Run(() => { Console.WriteLine("Build Electron Application..."); SimpleCommandLineParser parser = new SimpleCommandLineParser(); parser.Parse(_args); var desiredPlatform = parser.Arguments[_paramTarget][0]; string specifiedFromCustom = string.Empty; if (desiredPlatform == "custom" && parser.Arguments[_paramTarget].Length > 1) { specifiedFromCustom = parser.Arguments[_paramTarget][1]; } string configuration = "Release"; if (parser.Arguments.ContainsKey(_paramDotNetConfig)) { configuration = parser.Arguments[_paramDotNetConfig][0]; } var platformInfo = GetTargetPlatformInformation.Do(desiredPlatform, specifiedFromCustom); Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid}..."); string tempPath = Path.Combine(Directory.GetCurrentDirectory(), "obj", "desktop", desiredPlatform); if (Directory.Exists(tempPath) == false) { Directory.CreateDirectory(tempPath); } Console.WriteLine("Executing dotnet publish in this directory: " + tempPath); string tempBinPath = Path.Combine(tempPath, "bin"); Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid} under {configuration}-Configuration..."); var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} -c {configuration} --output \"{tempBinPath}\"", Directory.GetCurrentDirectory()); if (resultCode != 0) { Console.WriteLine("Error occurred during dotnet publish: " + resultCode); return false; } DeployEmbeddedElectronFiles.Do(tempPath); var nodeModulesDirPath = Path.Combine(tempPath, "node_modules"); if (parser.Arguments.ContainsKey(_paramPackageJson)) { Console.WriteLine("Copying custom package.json."); File.Copy(parser.Arguments[_paramPackageJson][0], Path.Combine(tempPath, "package.json"), true); } var checkForNodeModulesDirPath = Path.Combine(tempPath, "node_modules"); if (Directory.Exists(checkForNodeModulesDirPath) == false || parser.Contains(_paramForceNodeInstall) || parser.Contains(_paramPackageJson)) { Console.WriteLine("Start npm install..."); } ProcessHelper.CmdExecute("npm install --production", tempPath); Console.WriteLine("ElectronHostHook handling started..."); string electronhosthookDir = Path.Combine(Directory.GetCurrentDirectory(), "ElectronHostHook"); if (Directory.Exists(electronhosthookDir)) { string hosthookDir = Path.Combine(tempPath, "ElectronHostHook"); DirectoryCopy.Do(electronhosthookDir, hosthookDir, true, new List <string>() { "node_modules" }); Console.WriteLine("Start npm install for hosthooks..."); ProcessHelper.CmdExecute("npm install", hosthookDir); // ToDo: Not sure if this runs under linux/macos ProcessHelper.CmdExecute(@"npx tsc -p . --sourceMap false", hosthookDir); } Console.WriteLine("Build Electron Desktop Application..."); // Specifying an absolute path supercedes a relative path string buildPath = Path.Combine(Directory.GetCurrentDirectory(), "bin", "desktop"); if (parser.Arguments.ContainsKey(_paramAbsoluteOutput)) { buildPath = parser.Arguments[_paramAbsoluteOutput][0]; } else if (parser.Arguments.ContainsKey(_paramOutputDirectory)) { buildPath = Path.Combine(Directory.GetCurrentDirectory(), parser.Arguments[_paramOutputDirectory][0]); } Console.WriteLine("Executing electron magic in this directory: " + buildPath); string electronArch = "x64"; if (parser.Arguments.ContainsKey(_paramElectronArch)) { electronArch = parser.Arguments[_paramElectronArch][0]; } string electronParams = ""; if (parser.Arguments.ContainsKey(_paramElectronParams)) { electronParams = parser.Arguments[_paramElectronParams][0]; } // ToDo: Make the same thing easer with native c# - we can save a tmp file in production code :) Console.WriteLine("Create electron-builder configuration file..."); ProcessHelper.CmdExecute($"node build-helper.js", tempPath); Console.WriteLine($"Package Electron App for Platform {platformInfo.ElectronPackerPlatform}..."); ProcessHelper.CmdExecute($"npx electron-builder . --config=./bin/electron-builder.json --{platformInfo.ElectronPackerPlatform} --{electronArch} -c.electronVersion=5.0.8 {electronParams}", tempPath); Console.WriteLine("... done"); return true; })); }
public static bool Contains(string value) => CommandLine.Contains(value);
public Task <bool> ExecuteAsync() { return(Task.Run(() => { Console.WriteLine("Build Electron Application..."); SimpleCommandLineParser parser = new SimpleCommandLineParser(); parser.Parse(_args); //This version will be shared between the dotnet publish and electron-builder commands string version = null; if (parser.Arguments.ContainsKey(_paramVersion)) { version = parser.Arguments[_paramVersion][0]; } if (!parser.Arguments.ContainsKey(_paramTarget) || parser.Arguments[_paramTarget].Length == 0) { Console.WriteLine($"Error: missing '{_paramTarget}' argument."); Console.WriteLine(COMMAND_ARGUMENTS); return false; } var desiredPlatform = parser.Arguments[_paramTarget][0]; string specifiedFromCustom = string.Empty; if (desiredPlatform == "custom" && parser.Arguments[_paramTarget].Length > 1) { specifiedFromCustom = parser.Arguments[_paramTarget][1]; } string configuration = "Release"; if (parser.Arguments.ContainsKey(_paramDotNetConfig)) { configuration = parser.Arguments[_paramDotNetConfig][0]; } var platformInfo = GetTargetPlatformInformation.Do(desiredPlatform, specifiedFromCustom); Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid}..."); string tempPath = Path.Combine(Directory.GetCurrentDirectory(), "obj", "desktop", desiredPlatform); if (Directory.Exists(tempPath) == false) { Directory.CreateDirectory(tempPath); } else { Directory.Delete(tempPath, true); Directory.CreateDirectory(tempPath); } Console.WriteLine("Executing dotnet publish in this directory: " + tempPath); string tempBinPath = Path.Combine(tempPath, "bin"); Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid} under {configuration}-Configuration..."); var dotNetPublishFlags = GetDotNetPublishFlags(parser, "false", "false"); var project = string.Empty; if (parser.Arguments.ContainsKey(_paramDotNetProject)) { project = parser.Arguments[_paramDotNetProject][0]; } var command = $"dotnet publish {project} -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {string.Join(' ', dotNetPublishFlags.Select(kvp => $"{kvp.Key}={kvp.Value}"))}"; // add any additional dotnet flags var dotnetFlags = GetDotNetArgs(parser); if (dotnetFlags.Any()) { command += " " + string.Join(" ", dotnetFlags); } // output the command Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(command); Console.ResetColor(); var resultCode = ProcessHelper.CmdExecute(command, Directory.GetCurrentDirectory()); if (resultCode != 0) { Console.WriteLine("Error occurred during dotnet publish: " + resultCode); return false; } DeployEmbeddedElectronFiles.Do(tempPath); if (parser.Arguments.ContainsKey(_paramPackageJson)) { Console.WriteLine("Copying custom package.json."); File.Copy(parser.Arguments[_paramPackageJson][0], Path.Combine(tempPath, "package.json"), true); } var checkForNodeModulesDirPath = Path.Combine(tempPath, "node_modules"); if (!Directory.Exists(checkForNodeModulesDirPath) || parser.Contains(_paramForceNodeInstall) || parser.Contains(_paramPackageJson)) { Console.WriteLine("Start npm install..."); ProcessHelper.CmdExecute("npm install --production", tempPath); } Console.WriteLine("ElectronHostHook handling started..."); string electronhosthookDir = Path.Combine(Directory.GetCurrentDirectory(), "ElectronHostHook"); if (Directory.Exists(electronhosthookDir)) { string hosthookDir = Path.Combine(tempPath, "ElectronHostHook"); DirectoryCopy.Do(electronhosthookDir, hosthookDir, true, new List <string>() { "node_modules" }); Console.WriteLine("Start npm install for hosthooks..."); ProcessHelper.CmdExecute("npm install", hosthookDir); // ToDo: Not sure if this runs under linux/macos ProcessHelper.CmdExecute(@"npx tsc -p . --sourceMap false", hosthookDir); } Console.WriteLine("Build Electron Desktop Application..."); // Specifying an absolute path supercedes a relative path string buildPath = Path.Combine(Directory.GetCurrentDirectory(), "bin", "desktop"); if (parser.Arguments.ContainsKey(_paramAbsoluteOutput)) { buildPath = parser.Arguments[_paramAbsoluteOutput][0]; } else if (parser.Arguments.ContainsKey(_paramOutputDirectory)) { buildPath = Path.Combine(Directory.GetCurrentDirectory(), parser.Arguments[_paramOutputDirectory][0]); } Console.WriteLine("Executing electron magic in this directory: " + buildPath); string electronArch = "x64"; if (platformInfo.NetCorePublishRid == "osx-arm64") //Apple Silicon Mac { electronArch = "arm64"; } if (parser.Arguments.ContainsKey(_paramElectronArch)) { electronArch = parser.Arguments[_paramElectronArch][0]; } var electronVersion = ""; if (parser.Arguments.ContainsKey(_paramElectronVersion)) { electronVersion = parser.Arguments[_paramElectronVersion][0]; } else { //try getting version from project foreach (var projectFile in Directory.GetFiles(Directory.GetCurrentDirectory(), "*.csproj")) { var projectXML = File.ReadAllText(projectFile); var match = Regex.Match(projectXML, @"<PackageReference\s+Include=""h5\.ElectronNET\.API""\s+Version=""([0-9\.]+)""\s+\/>"); if (match.Success) { var candidate = match.Groups[1].Value; var majorMinorRevision = string.Join(".", candidate.Split(new char[] { '.' }).Take(3)); electronVersion = majorMinorRevision; Console.WriteLine($"Found electron version {majorMinorRevision} in project file {projectFile}"); break; } } } if (string.IsNullOrWhiteSpace(electronVersion)) { electronVersion = _defaultElectronVersion; } string electronParams = ""; if (parser.Arguments.ContainsKey(_paramElectronParams)) { electronParams = parser.Arguments[_paramElectronParams][0]; } // ToDo: Make the same thing easer with native c# - we can save a tmp file in production code :) Console.WriteLine("Create electron-builder configuration file..."); string manifestFileName = "electron.manifest.json"; if (parser.Arguments.ContainsKey(_manifest)) { manifestFileName = parser.Arguments[_manifest].First(); } ProcessHelper.CmdExecute( string.IsNullOrWhiteSpace(version) ? $"node build-helper.js {manifestFileName}" : $"node build-helper.js {manifestFileName} {version}", tempPath); Console.WriteLine($"Package Electron App for Platform {platformInfo.ElectronPackerPlatform}..."); ProcessHelper.CmdExecute($"npx electron-builder --config=./bin/electron-builder.json --{platformInfo.ElectronPackerPlatform} --{electronArch} -c.electronVersion={electronVersion} {electronParams}", tempPath); Console.WriteLine("... done"); return true; })); }