Skip to content
This repository was archived by the owner on Oct 5, 2019. It is now read-only.

Commit c8eeccb

Browse files
author
Zaczero
committed
Minor renaming, added directory config
1 parent bb71792 commit c8eeccb

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

SharpLoader/Program.cs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ public class Program
1313

1414
/* Limitations:
1515
* doesn't support $ strings
16+
* doesn't support @ strings
1617
* doesn't support VS code
17-
* doesn't support => properties
18+
* doesn't support => properties
19+
* doesn't support few unicode values
1820
*/
1921

2022
/* Exit codes:
@@ -26,15 +28,13 @@ public class Program
2628
* 5 - source file not found
2729
*/
2830

29-
// todo zip
30-
3131
private const string Author = "Zaczero";
3232
private const string Version = "1.0";
3333

3434
private const int ReadBufferSize = 255;
3535

36-
private const string DataFileName = "SharpLoader.ini";
37-
private static readonly string DataPath = Path.Combine(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName), DataFileName);
36+
private const string ConfigFileName = "SharpLoader.ini";
37+
private static readonly string ConfigPath = Path.Combine(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName), ConfigFileName);
3838

3939
public static void Main(string[] args)
4040
{
@@ -74,19 +74,20 @@ public static void Main(string[] args)
7474
Console.WriteLine();
7575

7676
// Data file not found
77-
if (!File.Exists(DataFileName))
77+
if (!File.Exists(ConfigFileName))
7878
{
7979
Console.ForegroundColor = ConsoleColor.Red;
80-
Console.WriteLine($"-=: Data file not found ({DataFileName})");
80+
Console.WriteLine($"-=: Config file not found ({ConfigFileName})");
8181

82-
WinApi.WritePrivateProfileString("SharpLoader", "Assemblies", "", DataPath);
83-
WinApi.WritePrivateProfileString("SharpLoader", "Sources", "", DataPath);
84-
WinApi.WritePrivateProfileString("SharpLoader", "Output", "SharpLoader", DataPath);
85-
WinApi.WritePrivateProfileString("SharpLoader", "AutoRun", "false", DataPath);
86-
WinApi.WritePrivateProfileString("SharpLoader", "Arguments", "/platform:anycpu32bitpreferred", DataPath);
82+
WinApi.WritePrivateProfileString("SharpLoader", "Assemblies", "", ConfigPath);
83+
WinApi.WritePrivateProfileString("SharpLoader", "Directory", "", ConfigPath);
84+
WinApi.WritePrivateProfileString("SharpLoader", "Sources", "", ConfigPath);
85+
WinApi.WritePrivateProfileString("SharpLoader", "Output", "SharpLoader", ConfigPath);
86+
WinApi.WritePrivateProfileString("SharpLoader", "AutoRun", "false", ConfigPath);
87+
WinApi.WritePrivateProfileString("SharpLoader", "Arguments", "/platform:anycpu32bitpreferred", ConfigPath);
8788

8889
Console.ForegroundColor = ConsoleColor.Red;
89-
Console.WriteLine($"-=: Default data file generated");
90+
Console.WriteLine($"-=: Default config file generated");
9091

9192
Console.ReadKey();
9293

@@ -96,18 +97,21 @@ public static void Main(string[] args)
9697
Console.ForegroundColor = ConsoleColor.White;
9798
Console.WriteLine("-=: Reading...");
9899

100+
var directoryReadSb = new StringBuilder(ReadBufferSize);
99101
var assembliesReadSb = new StringBuilder(ReadBufferSize);
100102
var sourceFilesReadSb = new StringBuilder(ReadBufferSize);
101103
var outputNameReadSb = new StringBuilder(ReadBufferSize);
102104
var autoRunReadSb = new StringBuilder(ReadBufferSize);
103105
var compilerArgumentsReadSb = new StringBuilder(ReadBufferSize);
104106

105-
WinApi.GetPrivateProfileString("SharpLoader", "Assemblies", string.Empty, assembliesReadSb, ReadBufferSize, DataPath);
106-
WinApi.GetPrivateProfileString("SharpLoader", "Sources", string.Empty, sourceFilesReadSb, ReadBufferSize, DataPath);
107-
WinApi.GetPrivateProfileString("SharpLoader", "Output", string.Empty, outputNameReadSb, ReadBufferSize, DataPath);
108-
WinApi.GetPrivateProfileString("SharpLoader", "AutoRun", string.Empty, autoRunReadSb, ReadBufferSize, DataPath);
109-
WinApi.GetPrivateProfileString("SharpLoader", "Arguments", string.Empty, compilerArgumentsReadSb, ReadBufferSize, DataPath);
107+
WinApi.GetPrivateProfileString("SharpLoader", "Directory", string.Empty, directoryReadSb, ReadBufferSize, ConfigPath);
108+
WinApi.GetPrivateProfileString("SharpLoader", "Assemblies", string.Empty, assembliesReadSb, ReadBufferSize, ConfigPath);
109+
WinApi.GetPrivateProfileString("SharpLoader", "Sources", string.Empty, sourceFilesReadSb, ReadBufferSize, ConfigPath);
110+
WinApi.GetPrivateProfileString("SharpLoader", "Output", string.Empty, outputNameReadSb, ReadBufferSize, ConfigPath);
111+
WinApi.GetPrivateProfileString("SharpLoader", "AutoRun", string.Empty, autoRunReadSb, ReadBufferSize, ConfigPath);
112+
WinApi.GetPrivateProfileString("SharpLoader", "Arguments", string.Empty, compilerArgumentsReadSb, ReadBufferSize, ConfigPath);
110113

114+
var directory = directoryReadSb.ToString();
111115
var assemblies = assembliesReadSb.ToString().Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
112116
var sourceFiles = sourceFilesReadSb.ToString().Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
113117
var outputName = $"{outputNameReadSb}-{DateTime.Now:dd-MM-yyyy}.exe";
@@ -149,6 +153,12 @@ public static void Main(string[] args)
149153
var sources = new string[sourceFiles.Length];
150154
for (var i = 0; i < sources.Length; i++)
151155
{
156+
// Add directory to source files paths
157+
if (!string.IsNullOrWhiteSpace(directory))
158+
{
159+
sourceFiles[i] = Path.Combine(directory, sourceFiles[i]);
160+
}
161+
152162
if (!File.Exists(sourceFiles[i]))
153163
{
154164
Console.ForegroundColor = ConsoleColor.Red;
@@ -175,8 +185,9 @@ public static void Main(string[] args)
175185

176186
compiler.Compile(outputName, compilerArguments, assemblies, sources);
177187

178-
if (autoRun)
188+
if (autoRun && File.Exists(outputName))
179189
{
190+
Console.WriteLine("-=: Starting...");
180191
Process.Start(outputName);
181192
}
182193

SharpLoader/SharpLoader.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
1212
<FileAlignment>512</FileAlignment>
1313
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<NuGetPackageImportStamp>
15+
</NuGetPackageImportStamp>
1416
</PropertyGroup>
1517
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1618
<PlatformTarget>AnyCPU</PlatformTarget>

0 commit comments

Comments
 (0)