New dev build

This commit is contained in:
2025-09-06 11:14:02 -05:00
parent 700cb81f24
commit 7c4f85ec21
28 changed files with 952 additions and 17 deletions

View File

@@ -3,8 +3,10 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Newtonsoft.Json;
@@ -14,6 +16,69 @@ namespace CrossLangDevStudio;
class CrossLangShell
{
public static string PackageServerFile = Path.Combine(CrossLangConfigDirectory, "package_servers.json");
public static List<string> GetServers()
{
if (File.Exists(PackageServerFile))
{
var res = JsonConvert.DeserializeObject<List<string>>(File.ReadAllText(PackageServerFile));
if (res is not null) return res;
}
return ["https://cpkg.tesseslanguage.com/"];
}
public static string[] ProjectTypes { get; } = ["console", "lib", "webapp", "template", "compile_tool", "tool", "archive"];
public static string[] ProjectProperTypes { get; } = ["Console Application","Library","Web Application","Template","Compile Tool","Tool","Archive"];
private static void EscapeBashElement(StringBuilder builder, string val)
{
builder.Append("\"");
foreach (var item in val)
{
switch (item)
{
case '$':
case '`':
case '\\':
case '\"':
case '!':
builder.Append('\\');
builder.Append(item);
break;
default:
builder.Append(item);
break;
}
}
builder.Append("\"");
}
private static string EscapeBashCommand(string name, string[] args)
{
StringBuilder builder = new StringBuilder();
EscapeBashElement(builder,name);
foreach (var item in args)
{
builder.Append(' ');
EscapeBashElement(builder,item);
}
builder.Append(" ; read -p \"Press Enter to close.\"");
return builder.ToString();
}
private static string EscapeMacBashCommand(string workDir, bool keepOpen,string name, string[] args)
{
StringBuilder builder = new StringBuilder();
builder.Append("cd ");
EscapeBashElement(builder, workDir);
builder.Append(" ; ");
EscapeBashElement(builder,name);
foreach (var item in args)
{
builder.Append(' ');
EscapeBashElement(builder,item);
}
if (keepOpen)
builder.Append(" ; read -p \"Press Enter to close.\"");
return builder.ToString();
}
private static CrossLangSettings? settings = null;
public static CrossLangSettings Settings
{
@@ -88,7 +153,15 @@ class CrossLangShell
}
public static string GetRealPath(string exec)
{
foreach (var item in (Environment.GetEnvironmentVariable("PATH") ?? "").Split(Path.PathSeparator))
var paths = (Environment.GetEnvironmentVariable("PATH") ?? "").Split(Path.PathSeparator).ToList();
var execDir = Environment.ProcessPath;
if (execDir is not null)
{
var dir = Path.GetDirectoryName(execDir);
if(dir is not null)
paths.Add(dir);
}
foreach (var item in paths)
{
var path = Path.Combine(item, exec);
if (File.Exists(path)) return path;
@@ -154,6 +227,10 @@ class CrossLangShell
{
string konsole = GetRealPath("konsole");
string gnome_terminal = GetRealPath("gnome-terminal");
string mate_terminal = GetRealPath("mate-terminal");
string lxterminal = GetRealPath("lxterminal");
string deepin_terminal = GetRealPath("deepin-terminal");
string xfce_terminal = GetRealPath("xfce4-terminal");
string xterm = GetRealPath("xterm");
if (File.Exists(konsole))
@@ -175,28 +252,185 @@ class CrossLangShell
}
process.Start();
}
if (File.Exists(xfce_terminal))
{
using Process process = new Process();
process.StartInfo.WorkingDirectory = workingDirectory;
process.StartInfo.FileName = xfce_terminal;
process.StartInfo.UseShellExecute = false;
if (commandName.Length != 0)
{
if (keepOpen)
process.StartInfo.ArgumentList.Add("--hold");
process.StartInfo.ArgumentList.Add("-e");
process.StartInfo.ArgumentList.Add(commandName);
foreach (var arg in args)
{
process.StartInfo.ArgumentList.Add(arg);
}
}
process.Start();
}
else if (File.Exists(gnome_terminal))
{
using Process process = new Process();
process.StartInfo.WorkingDirectory = workingDirectory;
process.StartInfo.FileName = gnome_terminal;
process.StartInfo.UseShellExecute = false;
if (commandName.Length != 0)
{
process.StartInfo.ArgumentList.Add("--");
if (keepOpen)
{
process.StartInfo.ArgumentList.Add("bash");
process.StartInfo.ArgumentList.Add("-c");
process.StartInfo.ArgumentList.Add(EscapeBashCommand(commandName, args));
}
else
{
process.StartInfo.ArgumentList.Add(commandName);
foreach (var arg in args)
{
process.StartInfo.ArgumentList.Add(arg);
}
}
}
process.Start();
}
else if (File.Exists(mate_terminal))
{
using Process process = new Process();
process.StartInfo.WorkingDirectory = workingDirectory;
process.StartInfo.FileName = mate_terminal;
process.StartInfo.UseShellExecute = false;
if (commandName.Length != 0)
{
process.StartInfo.ArgumentList.Add("--");
if (keepOpen)
{
process.StartInfo.ArgumentList.Add("bash");
process.StartInfo.ArgumentList.Add("-c");
process.StartInfo.ArgumentList.Add(EscapeBashCommand(commandName, args));
}
else
{
process.StartInfo.ArgumentList.Add(commandName);
foreach (var arg in args)
{
process.StartInfo.ArgumentList.Add(arg);
}
}
}
process.Start();
}
else if (File.Exists(lxterminal))
{
using Process process = new Process();
process.StartInfo.WorkingDirectory = workingDirectory;
process.StartInfo.FileName = lxterminal;
process.StartInfo.UseShellExecute = false;
if (commandName.Length != 0)
{
process.StartInfo.ArgumentList.Add("-e");
if (keepOpen)
{
process.StartInfo.ArgumentList.Add("bash");
process.StartInfo.ArgumentList.Add("-c");
process.StartInfo.ArgumentList.Add(EscapeBashCommand(commandName, args));
}
else
{
process.StartInfo.ArgumentList.Add(commandName);
foreach (var arg in args)
{
process.StartInfo.ArgumentList.Add(arg);
}
}
}
process.Start();
}
else if (File.Exists(deepin_terminal))
{
using Process process = new Process();
process.StartInfo.WorkingDirectory = workingDirectory;
process.StartInfo.FileName = deepin_terminal;
process.StartInfo.UseShellExecute = false;
if (commandName.Length != 0)
{
if (keepOpen)
process.StartInfo.ArgumentList.Add("--keep-open");
process.StartInfo.ArgumentList.Add("-e");
process.StartInfo.ArgumentList.Add(commandName);
foreach (var arg in args)
{
process.StartInfo.ArgumentList.Add(arg);
}
}
process.Start();
}
else if (File.Exists(xterm))
{
using Process process = new Process();
process.StartInfo.WorkingDirectory = workingDirectory;
process.StartInfo.FileName = xterm;
process.StartInfo.UseShellExecute = false;
if (commandName.Length != 0)
{
if (keepOpen)
process.StartInfo.ArgumentList.Add("-hold");
process.StartInfo.ArgumentList.Add("-e");
process.StartInfo.ArgumentList.Add(commandName);
foreach (var arg in args)
{
process.StartInfo.ArgumentList.Add(arg);
}
}
process.Start();
}
}
else if (OperatingSystem.IsWindows())
{
using Process process = new Process();
process.StartInfo.FileName = GetRealPath("cmd.exe");
if(commandName.Length > 0)
process.StartInfo.ArgumentList.Add(keepOpen ? "/K" : "/C");
if (commandName.Length > 0)
process.StartInfo.ArgumentList.Add(keepOpen ? "/K" : "/C");
process.StartInfo.CreateNoWindow = false;
process.StartInfo.UseShellExecute = false;
process.StartInfo.WorkingDirectory = workingDirectory;
if(commandName.Length > 0)
process.StartInfo.ArgumentList.Add(commandName);
foreach (var item in args)
process.StartInfo.ArgumentList.Add(item);
if (commandName.Length > 0)
process.StartInfo.ArgumentList.Add(commandName);
if (commandName.Length > 0)
foreach (var item in args)
process.StartInfo.ArgumentList.Add(item);
process.Start();
}
else if (OperatingSystem.IsMacOS())
{
using Process process = new Process();
process.StartInfo.WorkingDirectory = workingDirectory;
process.StartInfo.FileName = GetRealPath("open");
process.StartInfo.UseShellExecute = false;
if (commandName.Length != 0)
{
process.StartInfo.ArgumentList.Add("-b");
process.StartInfo.ArgumentList.Add("com.apple.terminal");
if (keepOpen)
{
process.StartInfo.ArgumentList.Add("bash");
process.StartInfo.ArgumentList.Add("-c");
process.StartInfo.ArgumentList.Add(EscapeMacBashCommand(workingDirectory, keepOpen, commandName, args));
}
else
{
process.StartInfo.ArgumentList.Add(commandName);
foreach (var arg in args)
{
process.StartInfo.ArgumentList.Add(arg);
}
}
}
process.Start();
}
}