Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unzip messes up file permissions on Mac. Can I run chmod myself?

Discussion in 'Scripting' started by MikeHergaarden, Sep 29, 2010.

  1. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    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:

    Code (csharp):
    1. chmod +x MYAPP.app/Contents/MacOS/MYAPP
    The unzip code:

    Code (csharp):
    1. private static bool UnzipStream(string outputFolder, string password, bool deleteZipFile, ZipInputStream s){
    2.             if (password != null  password != String.Empty)
    3.                 s.Password = password;
    4.             ZipEntry theEntry;
    5.             //string tmpEntry = String.Empty;
    6.             while ((theEntry = s.GetNextEntry()) != null)
    7.             {
    8.                
    9.                 string directoryName = outputFolder;
    10.                 string fileName = Path.GetFileName(theEntry.Name);
    11.                 // create directory
    12.                 if (directoryName != "")
    13.                 {
    14.                     Directory.CreateDirectory(directoryName);
    15.                 }
    16.                 if (fileName != String.Empty)
    17.                 {
    18.                     if (theEntry.Name.IndexOf(".ini") < 0)
    19.                     {
    20.                        
    21.                         string fullPath = directoryName + "\\" + theEntry.Name;
    22.                         fullPath = fullPath.Replace("\\ ", "\\");
    23.                         string fullDirPath = Path.GetDirectoryName(fullPath);
    24.                         if (!Directory.Exists(fullDirPath)) Directory.CreateDirectory(fullDirPath);
    25.                         FileStream streamWriter = File.Create(fullPath);
    26.                         int size = 2048;
    27.                         byte[] data = new byte[2048];
    28.                         while (true)
    29.                         {
    30.                             size = s.Read(data, 0, data.Length);
    31.                             if (size > 0)
    32.                             {
    33.                                 streamWriter.Write(data, 0, size);
    34.                             }
    35.                             else
    36.                             {
    37.                                 break;
    38.                             }
    39.                         }
    40.                         streamWriter.Close();
    41.                     }
    42.                 }
    43.             }
    44.             s.Close();
    45.             return true;
    46.         }
    I believe the File.Create() call cannot create a file with execute permissions, see: http://www.mail-archive.com/mono-devel-list@lists.ximian.com/msg21088.html.

    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.
     
    Last edited: Sep 30, 2010
  2. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    Mono.Unix.Native.Syscall.chmod("Cubelands", Mono.Unix.Native.FilePermissions.ALLPERMS);

    Compiled, however at runtime it complains about missing `MonoPosixHelper'. Adding libMonoPosixHelper complains about missing mscrvt (or something like that) which is a windows thingy :/.
     
    Last edited: Sep 30, 2010
  3. Ox_

    Ox_

    Joined:
    Jun 9, 2013
    Posts:
    93
    How did you get access to Mono.Unix.Native? I don't even have "Mono"...

    UPD: found this - running chmod via System.Diagnostics.Process
     
    Last edited: Jan 18, 2016