2using System.Collections.Generic;
3using System.Diagnostics;
14 UDebug.Log($
"Initializing class {GetType().Name}");
19 UDebug.Log($
"[{GetType().Name}] Opening url {url}");
20 if (
string.IsNullOrEmpty(url))
22 UDebug.Log(
"Url is empty or null.");
26 Application.OpenURL(url);
30 public override bool OpenApplication(
string applicationPath,
string[] argumentKeys,
string[] argumentValues)
32 if (!
string.IsNullOrEmpty(applicationPath))
34 UDebug.Log(
"Application is empty.");
38 if (!File.Exists(applicationPath))
40 UDebug.Log($
"Application does not exist at {applicationPath}");
44 int argumentCount = Mathf.Max(argumentKeys.Length, argumentValues.Length);
45 if (argumentKeys.Length != argumentValues.Length)
47 UDebug.LogWarning(
"The number of argument keys and values are not equal. Extra arguments will not be provided and mapping could be messed up.");
50 string arguments =
"";
51 for (
int argumentIndex = 0; argumentIndex < argumentCount; argumentIndex++)
53 if (argumentIndex > 0)
58 arguments += $
"-{argumentKeys[argumentIndex]} \"{argumentValues[argumentIndex]}\"";
61 using (Process process =
new Process())
63 process.StartInfo.WorkingDirectory = applicationPath;
64 process.StartInfo.Arguments = arguments;
65 process.StartInfo.FileName = applicationPath;
76 return new Dictionary<string, string>();
78 string[] args = System.Environment.GetCommandLineArgs();
80 UDebug.Log($
"First argument: {args[0]}");
84 string urlData = args[1];
85 UDebug.Log(
"[PixoWindowsPlatformUtilities] Parse from URL.");
89 UDebug.Log(
"[PixoWindowsPlatformUtilities] Parsing arguments from commandline.");
90 Dictionary<string, string> parameters =
new Dictionary<string, string>();
93 for(
int argumentIndex = 1; argumentIndex < args.Length; argumentIndex++)
95 if (args[argumentIndex].StartsWith(
'-') && ((argumentIndex + 1) < args.Length))
97 parameters.Add(args[argumentIndex].Remove(0), args[argumentIndex + 1]);
108 if (
string.IsNullOrEmpty(fileName))
110 UDebug.LogError(
"File name is null or empty.");
115 string path = Path.Combine(Application.persistentDataPath, fileName);
119 if (!File.Exists(path))
121 UDebug.LogError($
"File not found at path: {path}");
126 data = File.ReadAllText(path);
131 UDebug.LogError($
"Failed to read file: {path}\nException: {ex.Message}");
137 public override bool ReadFile(
string fileName, out
byte[] data)
139 if (
string.IsNullOrEmpty(fileName))
141 UDebug.LogError(
"File name is null or empty.");
146 string path = Path.Combine(Application.persistentDataPath, fileName);
150 if (!File.Exists(path))
152 UDebug.LogError($
"File not found at path: {path}");
157 data = File.ReadAllBytes(path);
162 UDebug.LogError($
"Failed to read file: {path}\nException: {ex.Message}");
168 public override bool WriteFile(
string fileName,
byte[] data)
170 if (
string.IsNullOrEmpty(fileName))
172 UDebug.LogError(
"File name is null or empty.");
177 if (data ==
null || data.Length == 0)
179 UDebug.LogError(
"No data provided to write.");
183 string path = Path.Combine(Application.persistentDataPath, fileName);
187 File.WriteAllBytes(path, data);
188 UDebug.Log($
"File saved successfully at: {path}");
193 UDebug.LogError($
"Failed to write file at {path}:\n{ex.Message}");
198 public override bool WriteStringToFile(
string fileName,
string data, System.Text.Encoding encoding =
null)
200 if (
string.IsNullOrEmpty(fileName))
202 UDebug.LogError(
"File name is null or empty.");
207 if (data ==
null || data.Length == 0)
209 UDebug.LogError(
"No data provided to write.");
213 string path = Path.Combine(Application.persistentDataPath, fileName);
219 File.WriteAllText(path, data);
223 File.WriteAllText(path, data, encoding);
226 UDebug.Log($
"File saved successfully at: {path}");
231 UDebug.LogError($
"Failed to write file at {path}:\n{ex.Message}");