I want my Patcher unity app to unzip some files(Another unity app). If i download and unzip this file manually all is fine. However, If I use my code to do so the permissions are read only and I can no longer execute the unzipped Unity application.
I need the Unity patch app to be able to run this on the extracted app:
chmod +x MYAPP.app/Contents/MacOS/MYAPP
The unzip code:
private static bool UnzipStream(string outputFolder, string password, bool deleteZipFile, ZipInputStream s){
if (password != null password != String.Empty)
s.Password = password;
ZipEntry theEntry;
//string tmpEntry = String.Empty;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = outputFolder;
string fileName = Path.GetFileName(theEntry.Name);
// create directory
if (directoryName != "")
{
Directory.CreateDirectory(directoryName);
}
if (fileName != String.Empty)
{
if (theEntry.Name.IndexOf(".ini") < 0)
{
string fullPath = directoryName + "\\" + theEntry.Name;
fullPath = fullPath.Replace("\\ ", "\\");
string fullDirPath = Path.GetDirectoryName(fullPath);
if (!Directory.Exists(fullDirPath)) Directory.CreateDirectory(fullDirPath);
FileStream streamWriter = File.Create(fullPath);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
streamWriter.Close();
}
}
}
s.Close();
return true;
}
I believe the File.Create() call cannot create a file with execute permissions, see: Re: [Mono-dev] FileSecurity or chmod.
Or can I manually call chmod somehow? This should be possible via Mono.Posix. But I don’t think Unity allows that?
I’m now thinking about having my Unity app start a seperate process that simply executes chmod on the unzipped files. It doesn’t seem to execute a .command app in a new process.