- Home /
Using chmod on Mac
Hi! I'm working on a game patcher where it would download a .zip file online, unzip the file and run it.
However, downloading and extracting the Mac archive messes up permissions and makes the resulting app non-executable. Research tells me to use 'chmod +x "filename"' to fix it, but most attempts to emulate the command with a file path results in a error where there's no such file or directory.
Here's the code for the part responsible for downloading and unzipping the .app bundle. I'm using UniZip for third party unarchiving, found here, by the way: http://forum.unity3d.com/threads/unizip-free-zipper-unzipper.220589/
I download the zip archive which is nicknamed 'gameDA.zip', unzip it into 'gameDA.app' inside the contents folder of the launcher's bundle, and I have to chmod 'gameDA' inside 'gameDA.app/Contents/MacOS'
The game launcher itself is called 'game launcher'.
#if UNITY_STANDALONE_OSX
IEnumerator DownloadGame() {
print ("Patch starting!");
PatchButton.GetComponent<Button>().interactable = false;
WWW patchwww = new WWW(MacURL);
WWW www = new WWW(VersionURL);
print ("Patch downloading!");
while (!patchwww.isDone) {
ProgressSlider.GetComponent<Slider>().value = patchwww.progress;
PatchButton.transform.Find("Text").GetComponent<Text>().text = (patchwww.progress * 100).ToString("F0") + "%";
yield return null;
}
if (patchwww.error != null) {
ProgressSlider.transform.Find("Background/Fill Area/Fill").GetComponent<Image>().color = Color.red;
}
System.IO.File.WriteAllBytes(Application.dataPath + "/version.txt", www.bytes);
System.IO.File.WriteAllBytes(Application.dataPath + "/gameDA.zip", patchwww.bytes);
ProgressSlider.GetComponent<Slider>().value = 1;
print ("Patch downloaded!");
ZipUtil.Unzip(Application.dataPath + "/gameDA.zip", Application.dataPath);
string pathToApp = Application.dataPath.Replace(" ", "\\ ") + "/gameDA.app/Contents/MacOS/gameDA";
print (pathToApp);
ProcessStartInfo chmodstart = new ProcessStartInfo() {
FileName = "chmod",
Arguments = "+x " + pathToApp,
};
Process chproc = new Process() {
StartInfo = chmodstart,
};
chproc.Start();
PlayButton.SetActive(true);
ProgressSlider.SetActive(false);
ReadyText.SetActive(true);
PatchButton.SetActive(false);
correctVersion = true;
System.IO.File.WriteAllText(Application.dataPath +"/version.txt", www.text);
}
#endif
The main part where the unzipping and my attempt to chmod happens here:
ZipUtil.Unzip(Application.dataPath + "/gameDA.zip", Application.dataPath);
string pathToApp = Application.dataPath.Replace(" ", "\\ ") + "/gameDA.app/Contents/MacOS/gameDA";
print (pathToApp);
ProcessStartInfo chmodstart = new ProcessStartInfo() {
FileName = "chmod",
Arguments = "+x " + pathToApp,
};
Process chproc = new Process() {
StartInfo = chmodstart,
};
chproc.Start();
Looking forward to a answer, and thanks for reading!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to open unity desktop app from web browser? 1 Answer
Making a bubble level (not a game but work tool) 1 Answer
Need help with launching mechanic 0 Answers