Skip to content

Commit b93754b

Browse files
committed
Support Windows
1 parent 5225acf commit b93754b

File tree

2 files changed

+56
-24
lines changed

2 files changed

+56
-24
lines changed

src/UselessAttributeStripper/Program.cs

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ private static int Main(string[] args)
1818
ShowUsage();
1919
return 1;
2020
}
21+
2122
Log("================================================================================");
2223
Log("Start! " + DateTime.Now);
2324
Log("================================================================================");
2425

25-
Dump(args);
26+
DumpArgs(args);
2627

2728
List<string> attributeNames;
2829
List<string> dllFileNames;
@@ -44,20 +45,23 @@ private static void ShowUsage()
4445
Console.WriteLine("https://github.com/SaladbowlCreative/Unity3D.UselessAttributeStripper");
4546
}
4647

47-
private static void Dump(string[] args)
48+
private static void DumpArgs(string[] args)
4849
{
4950
Log(string.Format("Exe: {0}", Assembly.GetExecutingAssembly().Location));
5051
Log(string.Format("Path: {0}", Environment.CurrentDirectory));
5152

52-
Log("---- ENVS-----");
53-
var variables = Environment.GetEnvironmentVariables();
54-
foreach (DictionaryEntry item in variables)
55-
Log(string.Format("{0}={1}", item.Key, item.Value));
56-
5753
Log("---- ARGS -----");
5854
for (var i = 0; i < args.Length; i++)
5955
Log(string.Format("args[{0}]='{1}'", i, args[i]));
56+
Log("---------------");
57+
}
6058

59+
private static void DumpEnvs()
60+
{
61+
Log("---- ENVS-----");
62+
var variables = Environment.GetEnvironmentVariables();
63+
foreach (DictionaryEntry item in variables)
64+
Log(string.Format("{0}={1}", item.Key, item.Value));
6165
Log("---------------");
6266
}
6367

@@ -130,9 +134,16 @@ private static void ProcessStrip(List<string> attributeNames, List<string> dllFi
130134
continue;
131135

132136
Log("- ProcessDll : " + dllFileName);
133-
stripper.ProcessDll(dllFileName);
134-
foreach (var item in stripper.StripCountMap.OrderByDescending(i => i.Value))
135-
Log(string.Format(" - {0} : {1}", item.Key, item.Value));
137+
try
138+
{
139+
stripper.ProcessDll(dllFileName);
140+
foreach (var item in stripper.StripCountMap.OrderByDescending(i => i.Value))
141+
Log(string.Format(" - {0} : {1}", item.Key, item.Value));
142+
}
143+
catch (Exception e)
144+
{
145+
Log(" - Failed: " + e);
146+
}
136147
}
137148

138149
// show summary
@@ -147,22 +158,43 @@ private static int SpawnOriginalExecutable(string[] args)
147158
try
148159
{
149160
var monoCfgDir = Environment.GetEnvironmentVariable("MONO_CFG_DIR");
150-
var monoPath = monoCfgDir.Substring(0, monoCfgDir.Length - 3) + "bin/mono";
151-
152-
var currentModulePath = Assembly.GetExecutingAssembly().Location;
153-
var orgModulePath = currentModulePath.Substring(0, currentModulePath.Length - 3) + "org.exe";
154-
155-
var orgArgs = '"' + orgModulePath + '"' + ' ' + string.Join(" ", args.Select(a => '"' + a + '"'));
156-
Log(string.Format("Spawn: Mono={0}", monoPath));
157-
Log(string.Format(" Exec={0}", orgModulePath));
158-
Log(string.Format(" Args={0}", orgArgs));
159-
var handle = Process.Start(monoPath, orgArgs);
160-
handle.WaitForExit();
161-
return handle.ExitCode;
161+
if (string.IsNullOrEmpty(monoCfgDir))
162+
{
163+
// Windows
164+
165+
var currentModulePath = Assembly.GetExecutingAssembly().Location;
166+
var orgModulePath = currentModulePath.Substring(0, currentModulePath.Length - 3) + "org.exe";
167+
168+
var orgArgs = string.Join(" ", args.Select(a => '"' + a + '"'));
169+
Log(string.Format("Spawn: Exec={0}", orgModulePath));
170+
Log(string.Format(" Args={0}", orgArgs));
171+
var handle = Process.Start(orgModulePath, orgArgs);
172+
handle.WaitForExit();
173+
return handle.ExitCode;
174+
}
175+
else
176+
{
177+
// OSX has env-values for running Mono
178+
// - MONO_PATH=/Applications/Unity531/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/mono/4.0
179+
// - MONO_CFG_DIR=/Applications/Unity531/Unity.app/Contents/Frameworks/MonoBleedingEdge/etc
180+
181+
var monoPath = monoCfgDir.Substring(0, monoCfgDir.Length - 3) + "bin/mono";
182+
var currentModulePath = Assembly.GetExecutingAssembly().Location;
183+
var orgModulePath = currentModulePath.Substring(0, currentModulePath.Length - 3) + "org.exe";
184+
185+
var orgArgs = '"' + orgModulePath + '"' + ' ' + string.Join(" ", args.Select(a => '"' + a + '"'));
186+
Log(string.Format("Spawn: Mono={0}", monoPath));
187+
Log(string.Format(" Exec={0}", orgModulePath));
188+
Log(string.Format(" Args={0}", orgArgs));
189+
var handle = Process.Start(monoPath, orgArgs);
190+
handle.WaitForExit();
191+
return handle.ExitCode;
192+
}
162193
}
163194
catch (Exception e)
164195
{
165196
Log(string.Format("SpawnOriginalExecutable got exception. Exception={0}", e));
197+
DumpEnvs();
166198
return 1;
167199
}
168200
}

src/UselessAttributeStripper/Properties/AssemblyInfo.cs

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

0 commit comments

Comments
 (0)