forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandLineFormatter.cs
More file actions
88 lines (81 loc) · 2.01 KB
/
Copy pathCommandLineFormatter.cs
File metadata and controls
88 lines (81 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEngine;
namespace UnityEditor.Scripting.Compilers
{
internal static class CommandLineFormatter
{
private static readonly Regex UnsafeCharsWindows = new Regex("[^A-Za-z0-9\\_\\-\\.\\:\\,\\/\\@\\\\]");
private static readonly Regex UnescapeableChars = new Regex("[\\x00-\\x08\\x10-\\x1a\\x1c-\\x1f\\x7f\\xff]");
private static readonly Regex Quotes = new Regex("\"");
public static string EscapeCharsQuote(string input)
{
string result;
if (input.IndexOf('\'') == -1)
{
result = "'" + input + "'";
}
else if (input.IndexOf('"') == -1)
{
result = "\"" + input + "\"";
}
else
{
result = null;
}
return result;
}
public static string PrepareFileName(string input)
{
string result;
if (Application.platform == RuntimePlatform.OSXEditor)
{
result = CommandLineFormatter.EscapeCharsQuote(input);
}
else
{
result = CommandLineFormatter.EscapeCharsWindows(input);
}
return result;
}
public static string EscapeCharsWindows(string input)
{
string result;
if (input.Length == 0)
{
result = "\"\"";
}
else if (CommandLineFormatter.UnescapeableChars.IsMatch(input))
{
Debug.LogWarning("Cannot escape control characters in string");
result = "\"\"";
}
else if (CommandLineFormatter.UnsafeCharsWindows.IsMatch(input))
{
result = "\"" + CommandLineFormatter.Quotes.Replace(input, "\"\"") + "\"";
}
else
{
result = input;
}
return result;
}
internal static string GenerateResponseFile(IEnumerable<string> arguments)
{
string uniqueTempPathInProject = FileUtil.GetUniqueTempPathInProject();
using (StreamWriter streamWriter = new StreamWriter(uniqueTempPathInProject))
{
foreach (string current in from a in arguments
where a != null
select a)
{
streamWriter.WriteLine(current);
}
}
return uniqueTempPathInProject;
}
}
}