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);
31 public override bool OpenApplication(
string applicationPath,
string[] argumentKeys,
string[] argumentValues)
33 if (!
string.IsNullOrEmpty(applicationPath))
35 UDebug.Log(
"Application is empty.");
39 if (!File.Exists(applicationPath))
41 UDebug.Log($
"Application does not exist at {applicationPath}");
45 int argumentCount = Mathf.Max(argumentKeys.Length, argumentValues.Length);
46 if (argumentKeys.Length != argumentValues.Length)
48 UDebug.LogWarning(
"The number of argument keys and values are not equal. Extra arguments will not be provided and mapping could be messed up.");
51 string arguments =
"";
52 for (
int argumentIndex = 0; argumentIndex < argumentCount; argumentIndex++)
54 if (argumentIndex > 0)
59 arguments += $
"-{argumentKeys[argumentIndex]} \"{argumentValues[argumentIndex]}\"";
62 using (Process process =
new Process())
64 process.StartInfo.WorkingDirectory = applicationPath;
65 process.StartInfo.Arguments = arguments;
66 process.StartInfo.FileName = applicationPath;
77 return new Dictionary<string, string>();
79 string[] args = System.Environment.GetCommandLineArgs();
81 UDebug.Log($
"First argument: {args[0]}");
85 string urlData = args[1];
86 UDebug.Log(
"[PixoWindowsPlatformUtilities] Parse from URL.");
90 UDebug.Log(
"[PixoWindowsPlatformUtilities] Parsing arguments from commandline.");
91 Dictionary<string, string> parameters =
new Dictionary<string, string>();
94 for(
int argumentIndex = 1; argumentIndex < args.Length; argumentIndex++)
96 if (args[argumentIndex].StartsWith(
'-') && ((argumentIndex + 1) < args.Length))
98 parameters.Add(args[argumentIndex].Remove(0), args[argumentIndex + 1]);
109 if (
string.IsNullOrEmpty(fileName))
111 UDebug.LogError(
"File name is null or empty.");
116 string path = Path.Combine(Application.persistentDataPath, fileName);
120 if (!File.Exists(path))
122 UDebug.LogError($
"File not found at path: {path}");
127 data = File.ReadAllText(path);
132 UDebug.LogError($
"Failed to read file: {path}\nException: {ex.Message}");
138 public override bool ReadFile(
string fileName, out
byte[] data)
140 if (
string.IsNullOrEmpty(fileName))
142 UDebug.LogError(
"File name is null or empty.");
147 string path = Path.Combine(Application.persistentDataPath, fileName);
151 if (!File.Exists(path))
153 UDebug.LogError($
"File not found at path: {path}");
158 data = File.ReadAllBytes(path);
163 UDebug.LogError($
"Failed to read file: {path}\nException: {ex.Message}");
169 public override bool WriteFile(
string fileName,
byte[] data)
171 if (
string.IsNullOrEmpty(fileName))
173 UDebug.LogError(
"File name is null or empty.");
178 if (data ==
null || data.Length == 0)
180 UDebug.LogError(
"No data provided to write.");
184 string path = Path.Combine(Application.persistentDataPath, fileName);
188 File.WriteAllBytes(path, data);
189 UDebug.Log($
"File saved successfully at: {path}");
194 UDebug.LogError($
"Failed to write file at {path}:\n{ex.Message}");
199 public override bool WriteStringToFile(
string fileName,
string data, System.Text.Encoding encoding =
null)
201 if (
string.IsNullOrEmpty(fileName))
203 UDebug.LogError(
"File name is null or empty.");
208 if (data ==
null || data.Length == 0)
210 UDebug.LogError(
"No data provided to write.");
214 string path = Path.Combine(Application.persistentDataPath, fileName);
220 File.WriteAllText(path, data);
224 File.WriteAllText(path, data, encoding);
227 UDebug.Log($
"File saved successfully at: {path}");
232 UDebug.LogError($
"Failed to write file at {path}:\n{ex.Message}");