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

Commit eb5cfc4

Browse files
author
Zaczero
committed
Revert "Revert "Added C# 7.0 support #4""
This reverts commit 4b6b2e5.
1 parent 4b6b2e5 commit eb5cfc4

File tree

9 files changed

+138
-22
lines changed

9 files changed

+138
-22
lines changed

SharpLoader/App.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
55
</startup>
6-
</configuration>
6+
</configuration>

SharpLoader/Core/RuntimeCompiler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.CodeDom.Compiler;
33
using System.Collections.Generic;
44
using System.Diagnostics;
5-
using Microsoft.CSharp;
5+
using Microsoft.CodeDom.Providers.DotNetCompilerPlatform;
66

77
namespace SharpLoader.Core
88
{
@@ -12,7 +12,7 @@ public class RuntimeCompiler
1212

1313
public RuntimeCompiler()
1414
{
15-
_compiler = new CSharpCodeProvider(new Dictionary<string, string> { { "CompilerVersion", "v4.0" } });
15+
_compiler = new CSharpCodeProvider();
1616
}
1717

1818
public bool Compile(string outputName, string compilerArguments, string[] assemblies, params string[] sources)

SharpLoader/FodyWeavers.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Weavers>
3+
<Costura />
4+
</Weavers>

SharpLoader/Program.cs

Lines changed: 92 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.IO.Compression;
66
using System.Linq;
7+
using System.Reflection;
78
using System.Runtime.InteropServices;
89
using System.Security.Cryptography;
910
using System.Text;
@@ -14,10 +15,6 @@ namespace SharpLoader
1415
{
1516
public static class Program
1617
{
17-
/* Limitations:
18-
* supports only c# 5.0
19-
*/
20-
2118
/* Exit codes:
2219
* 0 - default
2320
* 1 - data file not found
@@ -38,18 +35,19 @@ public static class Program
3835
private const int SW_SHOW = 5;
3936

4037
public const string Author = "Zaczero";
41-
public const string Version = "2.0.1";
38+
public const string Version = "2.1";
4239

4340
private const int ReadBufferSize = ushort.MaxValue;
4441

4542
private const string ConfigFileName = "SharpLoader.ini";
4643
private static readonly string MyPath = Process.GetCurrentProcess().MainModule.FileName;
4744
private static readonly string MyDirectory = Path.GetDirectoryName(MyPath);
48-
public static string ConfigPath = Path.Combine(MyDirectory, ConfigFileName);
45+
public static string ConfigPath;
4946

5047
public static List<string> DragDropPaths;
5148
public static int Seed = -1;
5249
public static string Hash;
50+
public static string SaveDir;
5351

5452
private static MainForm _form;
5553
private static bool _outToConsole;
@@ -69,7 +67,7 @@ public static void Main(string[] args)
6967
for (var i = 0; i < args.Length; i++)
7068
{
7169
// Argument is path
72-
if (args[i] != MyPath && (File.Exists(args[i]) || Directory.Exists(args[i])))
70+
if ((File.Exists(args[i]) || Directory.Exists(args[i])) && Path.GetExtension(args[i]) != ".exe")
7371
{
7472
// Directory
7573
if (File.GetAttributes(args[i]).HasFlag(FileAttributes.Directory))
@@ -94,6 +92,12 @@ public static void Main(string[] args)
9492
// Normal argument
9593
else
9694
{
95+
if (args[i] == "-cmd")
96+
{
97+
cmdMode = true;
98+
continue;
99+
}
100+
97101
// Multiple arguments
98102
if (i + 1 < args.Length)
99103
{
@@ -105,14 +109,12 @@ public static void Main(string[] args)
105109
{
106110
throw new Exception($"invalid seed value: {args[i + 1]}");
107111
}
112+
i++;
108113
}
109-
}
110-
// Single argument
111-
else
112-
{
113-
if (args[i] == "-cmd")
114+
else if (args[i] == "-path")
114115
{
115-
cmdMode = true;
116+
SaveDir = args[i + 1];
117+
i++;
116118
}
117119
}
118120
}
@@ -124,6 +126,18 @@ public static void Main(string[] args)
124126
Seed = new Random(Environment.TickCount).Next(0, int.MaxValue);
125127
}
126128

129+
if (string.IsNullOrEmpty(SaveDir))
130+
{
131+
ConfigPath = Path.Combine(MyDirectory, ConfigFileName);
132+
SaveDir = MyDirectory;
133+
}
134+
else
135+
{
136+
ConfigPath = Path.Combine(SaveDir, ConfigFileName);
137+
}
138+
139+
DumpToAppData();
140+
127141
// Show UI
128142
if (!cmdMode)
129143
{
@@ -161,6 +175,55 @@ public static void Main(string[] args)
161175
}
162176
}
163177

178+
public static void DumpToAppData()
179+
{
180+
var appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SharpLoader");
181+
var exePath = Path.Combine(appDataPath, "SharpLoader.exe");
182+
var thisPath = Process.GetCurrentProcess().MainModule.FileName;
183+
184+
if (thisPath != exePath)
185+
{
186+
if (!Directory.Exists(appDataPath))
187+
{
188+
Directory.CreateDirectory(appDataPath);
189+
}
190+
191+
// Run the newest file
192+
File.Copy(thisPath, exePath, true);
193+
194+
var argsString = string.Empty;
195+
foreach (var arg in Environment.GetCommandLineArgs())
196+
{
197+
if (File.Exists(arg))
198+
{
199+
argsString += $"\"{arg}\" ";
200+
}
201+
else
202+
{
203+
argsString += $"{arg} ";
204+
}
205+
}
206+
argsString = argsString.TrimEnd(' ');
207+
208+
Process.Start(exePath, $"{argsString} -path \"{SaveDir}\"");
209+
Environment.Exit(0);
210+
}
211+
212+
var binPath = Path.Combine(appDataPath, "bin");
213+
var binZipPath = Path.Combine(appDataPath, "bin.zip");
214+
215+
if (!Directory.Exists(binPath))
216+
{
217+
if (!File.Exists(binZipPath))
218+
{
219+
WriteResourceToFile("SharpLoader.bin.zip", binZipPath);
220+
}
221+
222+
ZipFile.ExtractToDirectory(binZipPath, binPath);
223+
File.Delete(binZipPath);
224+
}
225+
}
226+
164227
public static int Compile()
165228
{
166229
var randomizer = new SourceRandomizer(Seed);
@@ -239,6 +302,8 @@ public static int Compile()
239302
return 2;
240303
}
241304

305+
outputName = Path.Combine(SaveDir, outputName);
306+
242307
// Read sources
243308
var userSourceFiles = new List<string>();
244309

@@ -410,8 +475,10 @@ public static int Compile()
410475
return 4;
411476
}
412477

478+
int.TryParse("lol", out int parseeed);
479+
413480
Console.ForegroundColor = ConsoleColor.Green;
414-
Out($"-=: Done [{outputName}] {(_outToConsole ? "(press any key to exit)" : string.Empty)}");
481+
Out($"-=: Done [{Path.GetFileName(outputName)}] {(_outToConsole ? "(press any key to exit)" : string.Empty)}");
415482

416483
var sourceBytes = new List<byte>();
417484
foreach (var s in compileSourceFiles)
@@ -482,6 +549,17 @@ public static void CleanTemp()
482549
}
483550
}
484551

552+
private static void WriteResourceToFile(string resourceName, string fileName)
553+
{
554+
using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
555+
{
556+
using (var file = new FileStream(fileName, FileMode.Create, FileAccess.Write))
557+
{
558+
resource.CopyTo(file);
559+
}
560+
}
561+
}
562+
485563
private static IEnumerable<string> GetFilesFromDirectory(string directory)
486564
{
487565
var dir = new DirectoryInfo(directory);

SharpLoader/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("2.0.1.0")]
35-
[assembly: AssemblyFileVersion("2.0.1.0")]
34+
[assembly: AssemblyVersion("2.1.0.0")]
35+
[assembly: AssemblyFileVersion("2.1.0.0")]

SharpLoader/SelectForm.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ private void ThemeKeyDown(object sender, KeyEventArgs e)
3232

3333
private void CloseClick(object sender, EventArgs e)
3434
{
35+
Program.CleanTemp();
3536
Application.Exit();
3637
}
3738

SharpLoader/SharpLoader.csproj

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.5\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.5\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
4+
<Import Project="packages\Microsoft.Net.Compilers.2.1.0\build\Microsoft.Net.Compilers.props" Condition="Exists('packages\Microsoft.Net.Compilers.2.1.0\build\Microsoft.Net.Compilers.props')" />
35
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
46
<PropertyGroup>
57
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -8,11 +10,12 @@
810
<OutputType>Exe</OutputType>
911
<RootNamespace>SharpLoader</RootNamespace>
1012
<AssemblyName>SharpLoader</AssemblyName>
11-
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
1214
<FileAlignment>512</FileAlignment>
1315
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1416
<NuGetPackageImportStamp>
1517
</NuGetPackageImportStamp>
18+
<TargetFrameworkProfile />
1619
</PropertyGroup>
1720
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1821
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -40,6 +43,13 @@
4043
<ApplicationManifest>app.manifest</ApplicationManifest>
4144
</PropertyGroup>
4245
<ItemGroup>
46+
<Reference Include="Costura, Version=1.6.2.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
47+
<HintPath>packages\Costura.Fody.1.6.2\lib\dotnet\Costura.dll</HintPath>
48+
<Private>False</Private>
49+
</Reference>
50+
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
51+
<HintPath>packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.5\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
52+
</Reference>
4353
<Reference Include="System" />
4454
<Reference Include="System.Data" />
4555
<Reference Include="System.Drawing" />
@@ -81,6 +91,8 @@
8191
</ItemGroup>
8292
<ItemGroup>
8393
<None Include="app.manifest" />
94+
<EmbeddedResource Include="bin.zip" />
95+
<None Include="packages.config" />
8496
<None Include="Properties\Resources.resx">
8597
<Generator>ResXFileCodeGenerator</Generator>
8698
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
@@ -97,5 +109,19 @@
97109
<DependentUpon>SelectForm.cs</DependentUpon>
98110
</EmbeddedResource>
99111
</ItemGroup>
112+
<ItemGroup>
113+
<None Include="FodyWeavers.xml" />
114+
</ItemGroup>
100115
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
116+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
117+
<PropertyGroup>
118+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
119+
</PropertyGroup>
120+
<Error Condition="!Exists('packages\Microsoft.Net.Compilers.2.1.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.Net.Compilers.2.1.0\build\Microsoft.Net.Compilers.props'))" />
121+
<Error Condition="!Exists('packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.5\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.5\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
122+
<Error Condition="!Exists('packages\Fody.2.1.0\build\netstandard1.0\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Fody.2.1.0\build\netstandard1.0\Fody.targets'))" />
123+
<Error Condition="!Exists('packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets'))" />
124+
</Target>
125+
<Import Project="packages\Fody.2.1.0\build\netstandard1.0\Fody.targets" Condition="Exists('packages\Fody.2.1.0\build\netstandard1.0\Fody.targets')" />
126+
<Import Project="packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets" Condition="Exists('packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets')" />
101127
</Project>

SharpLoader/bin.zip

6.56 MB
Binary file not shown.

SharpLoader/packages.config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Costura.Fody" version="1.6.2" targetFramework="net462" developmentDependency="true" />
4+
<package id="Fody" version="2.1.0" targetFramework="net462" developmentDependency="true" />
5+
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.5" targetFramework="net462" />
6+
<package id="Microsoft.Net.Compilers" version="2.1.0" targetFramework="net462" developmentDependency="true" />
7+
</packages>

0 commit comments

Comments
 (0)