Skip to content

Commit

Permalink
add env
Browse files Browse the repository at this point in the history
  • Loading branch information
GoombaProgrammer committed Aug 12, 2023
1 parent bf68b65 commit c594de7
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 9 deletions.
12 changes: 11 additions & 1 deletion Eaucool.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ VisualStudioVersion = 17.6.33829.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eaucool", "Eaucool.csproj", "{68D13A82-41A1-433A-A1DB-7DAED73F3422}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eaupak", "eaupak\eaupak.csproj", "{1E598134-FBC4-4493-BDAC-584EAE8A6270}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "eaupak", "eaupak\eaupak.csproj", "{1E598134-FBC4-4493-BDAC-584EAE8A6270}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eauenv", "..\Eauenv\Eauenv.csproj", "{D564E921-45E1-45D6-A42B-D72692C97E24}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -31,6 +33,14 @@ Global
{1E598134-FBC4-4493-BDAC-584EAE8A6270}.Release|Any CPU.Build.0 = Release|Any CPU
{1E598134-FBC4-4493-BDAC-584EAE8A6270}.Release|x64.ActiveCfg = Release|Any CPU
{1E598134-FBC4-4493-BDAC-584EAE8A6270}.Release|x64.Build.0 = Release|Any CPU
{D564E921-45E1-45D6-A42B-D72692C97E24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D564E921-45E1-45D6-A42B-D72692C97E24}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D564E921-45E1-45D6-A42B-D72692C97E24}.Debug|x64.ActiveCfg = Debug|Any CPU
{D564E921-45E1-45D6-A42B-D72692C97E24}.Debug|x64.Build.0 = Debug|Any CPU
{D564E921-45E1-45D6-A42B-D72692C97E24}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D564E921-45E1-45D6-A42B-D72692C97E24}.Release|Any CPU.Build.0 = Release|Any CPU
{D564E921-45E1-45D6-A42B-D72692C97E24}.Release|x64.ActiveCfg = Release|Any CPU
{D564E921-45E1-45D6-A42B-D72692C97E24}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
14 changes: 14 additions & 0 deletions Eauenv/Eauenv.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<!-- If on Windows, define WINDOWS -->
<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
<DefineConstants>WINDOWS</DefineConstants>
</PropertyGroup>
</Project>
61 changes: 61 additions & 0 deletions Eauenv/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Diagnostics;
using System.IO.Compression;
using System.Net;

namespace Eauenv
{
internal class Program
{
static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Usage: eauenv <environment name>");
Console.WriteLine("If the environment does not exist, it will be created.");
return;
}
// Get the environment name
string envName = args[0];

// Check if userprofile/.eauenv exists
if (!Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".eauenv")))
{
Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".eauenv"));
}

// Check if the environment exists
if (!Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".eauenv", envName)))
{
Console.WriteLine("Creating environment " + envName);
// Create the environment
Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".eauenv", envName));
// Create the shell
#if WINDOWS
File.WriteAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".eauenv", envName, "shell.bat"), "@echo off\nset PATH=%PATH%;" + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".eauenv", envName) + "\n");
File.AppendAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".eauenv", envName, "shell.bat"), "set PATH=%PATH%;" + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".eauenv", envName) + "\\bin\n");
#else
File.WriteAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".eauenv", envName, "shell.sh"), "export PATH=$PATH:" + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".eauenv", envName) + "\n");
File.AppendAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".eauenv", envName, "shell.sh"), "export PATH=$PATH:" + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".eauenv", envName) + "/bin\n");
#endif
Console.WriteLine("Downloading latest Eaucool release...");
// Download latest Eaucool release
WebClient client = new WebClient();
#if WINDOWS
client.DownloadFile("https://www.github.com/Novixx-Systems/eaucool/releases/latest/download/windows.zip", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".eauenv", envName, "eaucool.zip"));
#else
client.DownloadFile("https://www.github.com/Novixx-Systems/eaucool/releases/latest/download/linux.zip", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".eauenv", envName, "eaucool.zip"));
#endif
Console.WriteLine("Extracting Eaucool...");
// Extract Eaucool
ZipFile.ExtractToDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".eauenv", envName, "eaucool.zip"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".eauenv", envName));
// Delete the zip
File.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".eauenv", envName, "eaucool.zip"));
// Done
Console.WriteLine("Created environment " + envName);
}
Console.Clear();
// Start shell
Process.Start(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".eauenv", envName, "shell.bat"));
}
}
}
2 changes: 1 addition & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ static void Main(string[] args)
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}

if (form == null) return;
while (form.Visible)
{
Application.DoEvents();
Expand Down
14 changes: 7 additions & 7 deletions Utilities/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static void Kw_Decrement()
{
// Decrement a variable by 1
string[] args = CodeParser.ParseLineIntoTokens(line);
string variable = Utils.GetString(args, 1);
string variable = args[1];

if (variable == string.Empty)
{
Expand All @@ -103,6 +103,7 @@ private static void Kw_Decrement()
{
Program.Error("Variable names must start with a $");
}
variable = variable.Substring(1);

if (!Program.variables.ContainsKey(variable))
{
Expand All @@ -122,7 +123,7 @@ private static void Kw_Increment()
{
// Increment a variable by 1
string[] args = CodeParser.ParseLineIntoTokens(line);
string variable = Utils.GetString(args, 1);
string variable = args[1];

if (variable == string.Empty)
{
Expand All @@ -133,6 +134,7 @@ private static void Kw_Increment()
{
Program.Error("Variable names must start with a $");
}
variable = variable.Substring(1);

if (!Program.variables.ContainsKey(variable))
{
Expand All @@ -152,21 +154,19 @@ private static void Kw_Rereplace()
{
// Replace a string with a regex
string[] args = CodeParser.ParseLineIntoTokens(line);
string variable = Utils.GetString(args, 1);
string variable = args[1];
string input = Utils.GetString(args, 2);
string pattern = Utils.GetString(args, 3);
string replacement = Utils.GetString(args, 4);

if (input == string.Empty || pattern == string.Empty || replacement == string.Empty)
{
return;
}

if (!variable.StartsWith("$"))
{
Program.Error("Variable names must start with a $");
}

variable = variable.Substring(1);

if (!Program.variables.ContainsKey(variable))
{
Program.variables.Add(variable, string.Empty);
Expand Down

0 comments on commit c594de7

Please sign in to comment.