Fix CSharp output paths on POSIX filesystems
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -10,6 +10,9 @@
|
|||||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
*.userprefs
|
*.userprefs
|
||||||
|
|
||||||
|
# User-specific files (VSCode)
|
||||||
|
.vscode
|
||||||
|
|
||||||
# Build results
|
# Build results
|
||||||
[Dd]ebug/
|
[Dd]ebug/
|
||||||
[Dd]ebugPublic/
|
[Dd]ebugPublic/
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace Il2CppInspector
|
|||||||
if (absolutePath.IndexOf("*", StringComparison.Ordinal) == -1)
|
if (absolutePath.IndexOf("*", StringComparison.Ordinal) == -1)
|
||||||
return absolutePath;
|
return absolutePath;
|
||||||
|
|
||||||
Regex sections = new Regex(@"((?:[^*]*)\\)((?:.*?)\*.*?)(?:$|\\)");
|
Regex sections = new Regex(string.Format(@"((?:[^*]*){0})((?:.*?)\*.*?)(?:$|{0})", Path.DirectorySeparatorChar));
|
||||||
var matches = sections.Matches(absolutePath);
|
var matches = sections.Matches(absolutePath);
|
||||||
|
|
||||||
var pathLength = 0;
|
var pathLength = 0;
|
||||||
@@ -32,7 +32,7 @@ namespace Il2CppInspector
|
|||||||
.OrderByDescending(x => x)
|
.OrderByDescending(x => x)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
path = dir + @"\";
|
path = dir + Path.DirectorySeparatorChar;
|
||||||
pathLength += match.Groups[1].Value.Length + match.Groups[2].Value.Length + 1;
|
pathLength += match.Groups[1].Value.Length + match.Groups[2].Value.Length + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ namespace Il2CppInspector.Outputs
|
|||||||
public void WriteFilesByNamespace<TKey>(string outPath, Func<TypeInfo, TKey> orderBy, bool flattenHierarchy) {
|
public void WriteFilesByNamespace<TKey>(string outPath, Func<TypeInfo, TKey> orderBy, bool flattenHierarchy) {
|
||||||
usedAssemblyAttributes.Clear();
|
usedAssemblyAttributes.Clear();
|
||||||
Parallel.ForEach(model.Assemblies.SelectMany(x => x.DefinedTypes).GroupBy(t => t.Namespace), ns => {
|
Parallel.ForEach(model.Assemblies.SelectMany(x => x.DefinedTypes).GroupBy(t => t.Namespace), ns => {
|
||||||
writeFile($"{outPath}\\{(!string.IsNullOrEmpty(ns.Key) ? ns.Key : "global").Replace('.', flattenHierarchy ? '.' : '\\')}.cs",
|
var relPath = !string.IsNullOrEmpty(ns.Key) ? ns.Key : "global";
|
||||||
|
writeFile(Path.Combine(outPath, (flattenHierarchy ? relPath : Path.Combine(relPath.Split('.'))) + ".cs"),
|
||||||
ns.OrderBy(orderBy));
|
ns.OrderBy(orderBy));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -61,9 +62,9 @@ namespace Il2CppInspector.Outputs
|
|||||||
usedAssemblyAttributes.Clear();
|
usedAssemblyAttributes.Clear();
|
||||||
Parallel.ForEach(model.Assemblies, asm => {
|
Parallel.ForEach(model.Assemblies, asm => {
|
||||||
// Sort namespaces into alphabetical order, then sort types within the namespaces by the specified sort function
|
// Sort namespaces into alphabetical order, then sort types within the namespaces by the specified sort function
|
||||||
if (writeFile($"{outPath}\\{asm.ShortName.Replace(".dll", "")}.cs", asm.DefinedTypes.OrderBy(t => t.Namespace).ThenBy(orderBy), outputAssemblyAttributes: !separateAttributes)
|
if (writeFile(Path.Combine(outPath, Path.GetFileNameWithoutExtension(asm.ShortName) + ".cs"), asm.DefinedTypes.OrderBy(t => t.Namespace).ThenBy(orderBy), outputAssemblyAttributes: !separateAttributes)
|
||||||
&& separateAttributes) {
|
&& separateAttributes) {
|
||||||
File.WriteAllText($"{outPath}\\AssemblyInfo_{asm.ShortName.Replace(".dll", "")}.cs", generateAssemblyInfo(new [] {asm}));
|
File.WriteAllText(Path.Combine(outPath, $"AssemblyInfo_{Path.GetFileNameWithoutExtension(asm.ShortName)}.cs"), generateAssemblyInfo(new [] {asm}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -71,8 +72,8 @@ namespace Il2CppInspector.Outputs
|
|||||||
public void WriteFilesByClass(string outPath, bool flattenHierarchy) {
|
public void WriteFilesByClass(string outPath, bool flattenHierarchy) {
|
||||||
usedAssemblyAttributes.Clear();
|
usedAssemblyAttributes.Clear();
|
||||||
Parallel.ForEach(model.Assemblies.SelectMany(x => x.DefinedTypes), type => {
|
Parallel.ForEach(model.Assemblies.SelectMany(x => x.DefinedTypes), type => {
|
||||||
writeFile($"{outPath}\\" + (type.Namespace + (type.Namespace.Length > 0 ? "." : "") + Regex.Replace(type.Name, "`[0-9]", ""))
|
string relPath = $"{type.Namespace}{(type.Namespace.Length > 0 ? "." : "")}{Regex.Replace(type.Name, "`[0-9]", "")}";
|
||||||
.Replace('.', flattenHierarchy ? '.' : '\\') + ".cs", new[] {type});
|
writeFile(Path.Combine(outPath, flattenHierarchy ? relPath : Path.Combine(relPath.Split('.')) + ".cs"), new[] {type});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,8 +85,8 @@ namespace Il2CppInspector.Outputs
|
|||||||
Parallel.ForEach(model.Assemblies.SelectMany(x => x.DefinedTypes),
|
Parallel.ForEach(model.Assemblies.SelectMany(x => x.DefinedTypes),
|
||||||
() => new HashSet<Assembly>(),
|
() => new HashSet<Assembly>(),
|
||||||
(type, _, used) => {
|
(type, _, used) => {
|
||||||
if (writeFile($"{outPath}\\{type.Assembly.ShortName.Replace(".dll", "")}\\" + (type.Namespace + (type.Namespace.Length > 0 ? "." : "") + Regex.Replace(type.Name, "`[0-9]", ""))
|
string relPath = Path.Combine($"{type.Namespace}{(type.Namespace.Length > 0 ? "." : "")}{Regex.Replace(type.Name, "`[0-9]", "")}".Split('.'));
|
||||||
.Replace('.', '\\') + ".cs", new[] {type}, outputAssemblyAttributes: !separateAttributes))
|
if (writeFile(Path.Combine(outPath, Path.GetFileNameWithoutExtension(type.Assembly.ShortName), $"{relPath}.cs"), new[] {type}, outputAssemblyAttributes: !separateAttributes))
|
||||||
used.Add(type.Assembly);
|
used.Add(type.Assembly);
|
||||||
return used;
|
return used;
|
||||||
},
|
},
|
||||||
@@ -96,7 +97,7 @@ namespace Il2CppInspector.Outputs
|
|||||||
|
|
||||||
if (separateAttributes && usedAssemblies.Any())
|
if (separateAttributes && usedAssemblies.Any())
|
||||||
foreach (var asm in usedAssemblies)
|
foreach (var asm in usedAssemblies)
|
||||||
File.WriteAllText($"{outPath}\\{asm.ShortName.Replace(".dll", "")}\\AssemblyInfo.cs", generateAssemblyInfo(new [] {asm}));
|
File.WriteAllText(Path.Combine(outPath, Path.GetFileNameWithoutExtension(asm.ShortName), "AssemblyInfo.cs"), generateAssemblyInfo(new [] {asm}));
|
||||||
|
|
||||||
return usedAssemblies;
|
return usedAssemblies;
|
||||||
}
|
}
|
||||||
@@ -115,8 +116,8 @@ namespace Il2CppInspector.Outputs
|
|||||||
|
|
||||||
foreach (var asm in assemblies) {
|
foreach (var asm in assemblies) {
|
||||||
var guid = Guid.NewGuid();
|
var guid = Guid.NewGuid();
|
||||||
var name = asm.ShortName.Replace(".dll", "");
|
var name = Path.GetFileNameWithoutExtension(asm.ShortName);
|
||||||
var csProjFile = $"{name}\\{name}.csproj";
|
var csProjFile = Path.Combine(name, $"{name}.csproj");
|
||||||
|
|
||||||
var def = Resources.SlnProjectDefinition
|
var def = Resources.SlnProjectDefinition
|
||||||
.Replace("%PROJECTGUID%", guid.ToString())
|
.Replace("%PROJECTGUID%", guid.ToString())
|
||||||
@@ -152,7 +153,7 @@ namespace Il2CppInspector.Outputs
|
|||||||
.Replace("%SCRIPTASSEMBLIES%", unityAssembliesPath)
|
.Replace("%SCRIPTASSEMBLIES%", unityAssembliesPath)
|
||||||
.Replace("%PROJECTREFERENCES%", referenceXml);
|
.Replace("%PROJECTREFERENCES%", referenceXml);
|
||||||
|
|
||||||
File.WriteAllText($"{outPath}\\{csProjFile}", csProj);
|
File.WriteAllText(Path.Combine(outPath, csProjFile), csProj);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge everything into .sln file
|
// Merge everything into .sln file
|
||||||
@@ -163,7 +164,7 @@ namespace Il2CppInspector.Outputs
|
|||||||
var filename = Path.GetFileName(outPath);
|
var filename = Path.GetFileName(outPath);
|
||||||
if (filename == "")
|
if (filename == "")
|
||||||
filename = "Il2CppProject";
|
filename = "Il2CppProject";
|
||||||
File.WriteAllText($"{outPath}\\{filename}.sln", sln);
|
File.WriteAllText(Path.Combine(outPath, $"{filename}.sln"), sln);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool writeFile(string outFile, IEnumerable<TypeInfo> types, bool useNamespaceSyntax = true, bool outputAssemblyAttributes = true) {
|
private bool writeFile(string outFile, IEnumerable<TypeInfo> types, bool useNamespaceSyntax = true, bool outputAssemblyAttributes = true) {
|
||||||
@@ -267,7 +268,7 @@ namespace Il2CppInspector.Outputs
|
|||||||
|
|
||||||
// Sanitize leafname (might be class name with invalid characters)
|
// Sanitize leafname (might be class name with invalid characters)
|
||||||
var leafname = Regex.Replace(Path.GetFileName(outFile), @"[<>:""\|\?\*]", "_");
|
var leafname = Regex.Replace(Path.GetFileName(outFile), @"[<>:""\|\?\*]", "_");
|
||||||
outFile = Path.GetDirectoryName(outFile) + Path.DirectorySeparatorChar + leafname;
|
outFile = Path.Combine(Path.GetDirectoryName(outFile), leafname);
|
||||||
|
|
||||||
// Create output file
|
// Create output file
|
||||||
bool fileWritten = false;
|
bool fileWritten = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user