DotNetZip under MacOS

Dec 22, 2010 at 1:22 PM
Edited Dec 22, 2010 at 1:23 PM

Hi all,

I have integrated DotNetZip in my Patcher project. All works fine until I'm unzipping my .app file.

The unzip code works well, but after that the application wont start! Any one idea that could it be?

File permission, or maybe plist problem? 

my code:

 

void Unzip ()
{
	try {
		using (ZipFile zf = ZipFile.Read ("update.zip")) {
			
			foreach (ZipEntry zEntry in zf) {
				
				if (!zEntry.FileName.StartsWith ("__")) {
					zEntry.Extract
                             (Directory.GetCurrentDirectory () + "/tmp", 
ExtractExistingFileAction.OverwriteSilently);
				}

			}
			zf.Dispose ();
		}
	} catch (System.Exception ex) {
		Debug.Log (ex);
		StartGame ();
	}
	finally
	{
		DeleteTemp ();
	}
}

 

 

 

 

Dec 23, 2010 at 12:18 AM

Hi Iwan,

Just a hunch here, but what actually makes your application start? If it's "StartGame()" then you might try moving it out of the "Catch" part of the Try ... Catch block and into the main "Try" part. The "Catch" part only runs if an error occurs in your program, so as your code stands at the moment it will only run if the unzip process *fails*.

As an aside, you also don't need the "zf.Dispose()", as that is called implicitly at the end of the "using" statement.

Hope this helps,

Mike

 

 

Dec 23, 2010 at 12:25 AM

Hi pointy,

 

no the probem isn't in code i have posted. The unzipping works fine. But unzipped .app won't launch. I've checked the content of app and that was same like in orginal file. So i have no idea why the app will not execute.

If I unpack with standard unzip on MacOS the app executing. So i think something while unzipiing going wrong, or its permission problem.

 

P.S: sorry for my bad english :D

Dec 23, 2010 at 12:54 AM

Hi Iwan,

It sounds like an OS-specific problem, so I'm not sure I can help in that case - I don't really use Macs, I'm afraid.

Did you create "update.zip" using DotNetZip? I'm totally guessing now, but it's possible that the zip file has some "embedded resource forks" which DotNetZip doesn't handle, but the native Mac OS unzip does. In that case there might be secondary data streams attached to the ".app" file which aren't being extracted from the zip by DotNetZip.

From http://xahlee.org/UnixResource_dir/macosx.html
"In Mac OS X, data files is not suppose to use resource forks, so that Mac's files is compatible with other OS, however, program executable files such as those “.app” may still need the resource fork intact to work, and many programs including Apple's still creates resource fork as of 2010-07".

Other than that, I'm not sure what else to suggest...

M

Dec 23, 2010 at 12:58 AM

Actually, that's probably what your "__" files are all about. They're probably resource forks ("alternate data streams" in NTFS-speak).

I've got no idea what they do or mean in Mac terms, but I suspect they're the best place to look for a solution...

Hope this helps,

M

Dec 23, 2010 at 1:03 AM
Edited Dec 23, 2010 at 1:08 AM
Ah thats makes sense. The zip was maked with macos. The code I've posted works fine on windows. Mac os saves "__MACOS" folder in the zip, maybe that's the fork. Thank you very much, I'll look for that tomorrow :) I'll post the result Thank you again P.S: if __MACOS folder is the fork, any idea how to connect that to my first stream?
Dec 23, 2010 at 2:07 AM

Cool. Let me know how you get on.

In terms of reconstructing the multi-stream file, it looks like the MacOS zip program stores the data fork and the resource fork as separate files in the *.zip. You can extract them using DotNetZip, but they'll appear as separate files in the output folder (the resource fork will be in the "__MACOS" sub-folder). You could extract both files to an NTFS drive using DotNetZip and then reconstruct the single file using the alternate data stream APIs (see some examples below):

http://support.microsoft.com/kb/105763
http://msdn.microsoft.com/en-us/magazine/cc163677.aspx

However, I don't know how this would appear to a Mac if you copied it to the local drive or tried to access it over a network.

Another option is to extract the streams and build a single file on an NTFS drive - there are at least two different file formats which incorporate the data and resource forks into a single data file for MacOS to consume:

http://en.wikipedia.org/wiki/MacBinary
http://en.wikipedia.org/wiki/AppleSingle_and_AppleDouble_formats

That's about as much help as I can offer down that road though, I'm afraid...

Cheers,

Mike

Dec 23, 2010 at 1:09 PM

Thank you very much for you help :)

I've found the solution. It was not the unzipping code. It was writing and execution permissions under MacOS. The Apps under MacOS are folders. The file in App/Content/MacOS need execution flag or execution permission, like rxw-rxw-rx

Im using Diagnostic.Process to call chmod after unzipping the File. Now it works! :)

 

P.S: if you want to be in Credits for our game give me short email and which name we should write in :)

Dec 23, 2010 at 1:13 PM

Hi Iwan,

Glad you found the answer you needed.

If you want to add credits in your game maybe just mention DotNetZip and add the codeplex url. That would be plenty.

Happy holidays,

Mike