Ejemplo n.º 1
0
    //A function that compresses a byte buffer and writes it to a zip file. I you set the append flag to true, the output will get appended to an existing zip archive.
    //
    //levelOfCompression    : (0-10) recommended 9 for maximum (10 is highest but slower and not zlib compatible)
    //zipArchive            : the full path to the zip archive to be created or append to.
    //arc_filename          : the name of the file that will be written to the archive.
    //buffer                : the buffer that will be compressed and will be put in the zip archive.
    //append                : set to true if you want the output to be appended to an existing zip archive.
    //
    //ERROR CODES           : true  = success
    //                      : false = failed
    //
    public static bool buffer2File(int levelOfCompression, string zipArchive, string arc_filename, byte[] buffer, bool append = false)
    {
        if (!append)
        {
            if (File.Exists(@zipArchive))
            {
                File.Delete(@zipArchive);
            }
        }
        GCHandle sbuf = GCHandle.Alloc(buffer, GCHandleType.Pinned);

        if (levelOfCompression < 0)
        {
            levelOfCompression = 0;
        }
        if (levelOfCompression > 10)
        {
            levelOfCompression = 10;
        }

        bool res = zipBuf2File(levelOfCompression, @zipArchive, arc_filename, sbuf.AddrOfPinnedObject(), buffer.Length);

        sbuf.Free();
        return(res);
    }
Ejemplo n.º 2
0
    //A function that compresses a file to a zip file. If the flag append is set to true then it will get appended to an existing zip file.
    //
    //levelOfCompression  : (0-10) recommended 9 for maximum (10 is highest but slower and not zlib compatible)
    //zipArchive          : the full path to the zip archive that will be created
    //inFilePath          : the full path to the file that should be compressed and added to the zip file.
    //append              : set to true if you want the input file to get appended to an existing zip file. (if the zip file does not exist it will be created.)
    //filename            : if you want the name of your file to be different then the one it has, set it here. If you add a folder structure to it,
    //                      like (dir1/dir2/myfile.bin) the directories will be created in the zip file.
    //comment             : add a comment for the file in the zip file header.
    //
    //ERROR CODES
    //                    : -1 = could not find the input file
    //                    : -2 = could not allocate memory
    //                    : -3 = could not read the input file
    //                    : -4 = error creating zip file
    //                    :  1 = success
    //
    public static int compress_File(int levelOfCompression, string zipArchive, string inFilePath, bool append = false, string fileName = "", string comment = "")
    {
        if (!append)
        {
            if (File.Exists(@zipArchive))
            {
                File.Delete(@zipArchive);
            }
        }
        if (!File.Exists(@inFilePath))
        {
            return(-10);
        }

        if (fileName == "")
        {
            fileName = Path.GetFileName(@inFilePath);
        }
        if (levelOfCompression < 0)
        {
            levelOfCompression = 0;
        }
        if (levelOfCompression > 10)
        {
            levelOfCompression = 10;
        }

        return(zipCD(levelOfCompression, @zipArchive, @inFilePath, fileName, comment));
    }
Ejemplo n.º 3
0
    IEnumerator DownloadTestFile()
    {
        Debug.Log("starting download");

        //make sure a previous flz file having the same name with the one we want to download does not exist in the ppath folder
        if (File.Exists(ppath + "/" + myFile))
        {
            File.Delete(ppath + "/" + myFile);
        }

        //replace the link to the flz file with your own (although this will work also)
        // string esc = WWW.UnEscapeURL(uri + myFile);
        www = new WWW(uri + myFile);
        yield return(www);

        if (www.error != null)
        {
            Debug.Log(www.error);
        }

        downloadDone = true;

        //write the downloaded flz file to the ppath directory so we can have access to it
        //depending on the Install Location you have set for your app, set the Write Access accordingly!
        File.WriteAllBytes(ppath + "/" + myFile, www.bytes);
        www.Dispose(); www = null;
    }
Ejemplo n.º 4
0
    IEnumerator Download7ZFile()
    {
        Debug.Log("starting download");

        //make sure a previous 7z file having the same name with the one we want to download does not exist in the ppath folder
        if (File.Exists(ppath + "/" + myFile))
        {
            File.Delete(ppath + "/" + myFile);
        }

        www = new WWW(uri + myFile);
        yield return(www);

        if (www.error != null)
        {
            Debug.Log(www.error);
        }
        downloadDone = true;
        log          = "";

        //write the downloaded 7z file to the ppath directory so we can have access to it
        //depending on the Install Location you have set for your app, set the Write Access accordingly!
        File.WriteAllBytes(ppath + "/" + myFile, www.bytes);
        www.Dispose(); www = null;
    }
Ejemplo n.º 5
0
	public IEnumerator DetectNotInstalledLevels()
	{
		isrunning=true;
		loading.SetActive (true);
		if (Application.platform == RuntimePlatform.IPhonePlayer) {
			if (Directory.Exists (Application.persistentDataPath + "/Inbox/")) {
				foreach (var file in Directory.GetFiles(Application.persistentDataPath + "/Inbox/", "*.demoidlevel")) {
					var toPath = Application.persistentDataPath + "/" + Path.GetFileName (file);
					if (File.Exists (toPath)) {
						File.Delete (toPath);
					}
					File.Move (file, toPath);
				}
			}
			if (LevelsInstalling == false) {
				StartCoroutine (InstallLevels ());
			}
		} else if (Application.platform == RuntimePlatform.Android) {
			if (LevelsInstalling == false) {
				StartCoroutine (InstallLevels ());
			}
		}

		while (LevelsInstalling == true)
			yield return null;
		loading.SetActive (false);
		isrunning=false;
    }
Ejemplo n.º 6
0
    //Compress a directory with all its files and subfolders to a zip file
    //
    //sourceDir             : the directory you want to compress
    //levelOfCompression    : the level of compression (0-10).
    //zipArchive            : the full path+name to the zip file to be created .
    //includeRoot           : set to true if you want the root folder of the directory to be included in the zip archive. Otherwise leave it to false.
    //
    //If you want to get the progress of compression, call the getAllFiles function to get the total number of files
    //in a directory and its subdirectories. The compressDir when called from a separate thread will update the public static int cProgress.
    //Divide this with the total no of files (as floats) and you have the % of the procedure.
    public static void compressDir(string sourceDir, int levelOfCompression, string zipArchive, Action <int, int, string> progress = null, bool includeRoot = false)
    {
        string fdir = @sourceDir.Replace("\\", "/");

        if (Directory.Exists(fdir))
        {
            if (File.Exists(@zipArchive))
            {
                File.Delete(@zipArchive);
            }
            string[] ss   = fdir.Split('/');
            string   rdir = ss[ss.Length - 1];
            string   root = rdir;

            cProgress = 0;

            if (levelOfCompression < 0)
            {
                levelOfCompression = 0;
            }
            if (levelOfCompression > 10)
            {
                levelOfCompression = 10;
            }

#if (UNITY_WSA_8_1 || UNITY_WP_8_1 || UNITY_WINRT_8_1) && !UNITY_EDITOR
            string[] files  = Directory.GetFiles(fdir);
            int      length = files.Length;
            foreach (string f in Directory.GetFiles(fdir))
            {
#else
            string[] files = Directory.GetFiles(fdir, "*", SearchOption.AllDirectories);
            int length     = files.Length;
            foreach (string f in files)
            {
#endif
                string s = f.Replace(fdir, rdir).Replace("\\", "/");
                if (!includeRoot)
                {
                    s = s.Replace(root + "/", "");
                }
                compress_File(levelOfCompression, @zipArchive, f, true, s);
                cProgress++;
                if (null != progress)
                {
                    progress(length, cProgress, f);
                }
            }
        }
    }
Ejemplo n.º 7
0
    // A function that deletes a file in a zip archive. It creates a temp file where the compressed data of the old archive is copied except the one that needs to be deleted.
    // After that the old zip archive is deleted and the temp file gets renamed to the original zip archive.
    // You can delete directories too if they are empty.
    //
    // zipArchive           : the full path to the zip archive
    // arc_filename         : the name of the file that will be deleted.
    //
    // ERROR CODES			:  1 = success
    //						: -1 = failed to open zip
    //						: -2 = failed to locate the archive to be deleted in the zip file
    //						: -3 = error copying compressed data from original zip
    //						: -4 = failed to create temp zip file.
    //
    public static int delete_entry(string zipArchive, string arc_filename)
    {
        string tmp = zipArchive + ".tmp";
        int    res = zipDeleteFile(@zipArchive, arc_filename, @tmp);

        if (res > 0)
        {
            File.Delete(@zipArchive);
            File.Move(@tmp, @zipArchive);
        }
        else
        {
            if (File.Exists(@tmp))
            {
                File.Delete(@tmp);
            }
        }

        return(res);
    }
Ejemplo n.º 8
0
    public static int zipFiles, zipFolders;                  // global integers that store the number of files and folders in a zip file.

    //This function fills the Lists with the filenames and file sizes that are in the zip file
    //Returns			: the total size of uncompressed bytes of the files in the zip archive
    //
    //zipArchive		: the full path to the archive, including the archives name. (/myPath/myArchive.zip)
    //path              : the path where a temporary file will be created (recommended to use the Application.persistentDataPath);
    //FileBuffer		: A buffer that holds a zip file. When assigned the function will read from this buffer and will ignore the filePath. (Linux, iOS, Android, MacOSX)
    //
    //ERROR CODES       : -1 = Input file not found
    //                  : -2 = Path to write the temporary log does not exist (for mobiles the Application.persistentDataPath is recommended)
    //                  : -3 = Error of info data of the zip file
    //                  : -4 = Log file not found
    //
    public static long getFileInfo(string zipArchive, string path, byte[] FileBuffer = null)
    {
        ninfo.Clear(); uinfo.Clear(); cinfo.Clear();
        zipFiles = 0; zipFolders = 0;

        int res;

#if (UNITY_IPHONE || UNITY_IOS || UNITY_STANDALONE_OSX || UNITY_ANDROID || UNITY_STANDALONE_LINUX || UNITY_EDITOR) && !UNITY_EDITOR_WIN
        if (FileBuffer != null)
        {
            GCHandle fbuf = GCHandle.Alloc(FileBuffer, GCHandleType.Pinned);
            res = zipGetInfo(null, @path, fbuf.AddrOfPinnedObject(), FileBuffer.Length);
            fbuf.Free();
        }
        else
        {
            res = zipGetInfo(@zipArchive, @path, IntPtr.Zero, 0);
        }
#else
        res = zipGetInfo(@zipArchive, @path, IntPtr.Zero, 0);
#endif


        if (res == -1) /*Debug.Log("Input file not found.");*/ return {
            (-1);
        }

#if (UNITY_WP8_1 || UNITY_WSA) && !UNITY_EDITOR
        if (!UnityEngine.Windows.Directory.Exists(@path)) /*Debug.Log("Path does not exist: " + path);*/ return {
            (-2);
        }
#else
        if (res == -2) /*Debug.Log("Path does not exist: " + path);*/ return {
            (-2);
        }
#endif
        if (res == -3) /*Debug.Log("Entry info error.");*/ return {
            (-3);
        }

        string logPath = @path + "/uziplog.txt";


        if (!File.Exists(logPath)) /*Debug.Log("Info file not found.");*/ return {
            (-4);
        }

#if !NETFX_CORE
        StreamReader r = new StreamReader(logPath);
#endif
#if NETFX_CORE
#if UNITY_WSA_10_0
        IsolatedStorageFile ipath = IsolatedStorageFile.GetUserStoreForApplication();
        StreamReader        r     = new StreamReader(new IsolatedStorageFileStream("uziplog.txt", FileMode.Open, ipath));
#endif
#if UNITY_WSA_8_1 || UNITY_WP_8_1 || UNITY_WINRT_8_1
        var          data = UnityEngine.Windows.File.ReadAllBytes(logPath);
        string       ss   = System.Text.Encoding.UTF8.GetString(data, 0, data.Length);
        StringReader r    = new StringReader(ss);
#endif
#endif
        string   line;
        string[] rtt;
        long     t = 0, sum = 0;

        while ((line = r.ReadLine()) != null)
        {
            rtt = line.Split('|');
            ninfo.Add(rtt[0]);

            long.TryParse(rtt[1], out t);
            sum += t;
            uinfo.Add(t);
            if (t > 0)
            {
                zipFiles++;
            }
            else
            {
                zipFolders++;
            }

            long.TryParse(rtt[2], out t);
            cinfo.Add(t);
        }

#if !NETFX_CORE
        r.Close();
#endif
        r.Dispose();

        File.Delete(logPath);

        return(sum);
    }
Ejemplo n.º 9
0
    //Test all the plugin functions.
    //
    void DoDecompression()
    {
        //----------------------------------------------------------------------------------------------------------------
        //commented out example on how to set the permissions of a MacOSX executbale that has been unzipped so it can run.
        //
        //lzip.setFilePermissions(ppath + "/Untitled.app", "rwx","rx","rx");
        //lzip.setFilePermissions(ppath + "/Untitled.app/Contents/MacOS/Untitled", "rwx","rx","rx");
        //
        //----------------------------------------------------------------------------------------------------------------

        //Windows & WSA10 only (see lzip.cs for more info)
                #if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_WSA)
        lzip.setEncoding(65001);        //CP_UTF8  // CP_OEMCP/UNICODE = 1
                #endif

        //validate sanity of a zip archive
        plog("Validate: " + lzip.validateFile(ppath + "/testZip.zip").ToString());


        //decompress the downloaded file
        zres = lzip.decompress_File(ppath + "/testZip.zip", ppath + "/", progress, null, progress2);
        plog("decompress: " + zres.ToString());
        plog("");

        //get the true total files of the zip
        plog("true total files: " + lzip.getTotalFiles(ppath + "/testZip.zip"));


        //get the total entries of the zip
        plog("true total entries: " + lzip.getTotalEntries(ppath + "/testZip.zip"));


        //entry exists
        bool eres = lzip.entryExists(ppath + "/testZip.zip", "dir1/dir2/test2.bmp");
        plog("entry exists: " + eres.ToString());


        //get entry dateTime
        plog("");
        plog("DateTime: " + lzip.entryDateTime(ppath + "/testZip.zip", "dir1/dir2/test2.bmp").ToString());


        //extract an entry
        zres = lzip.extract_entry(ppath + "/testZip.zip", "dir1/dir2/test2.bmp", ppath + "/test22P.bmp", null, progress2);
        plog("extract entry: " + zres.ToString());

        plog("");



        //compress a file and add it to a new zip
        zres = lzip.compress_File(9, ppath + "/test2Zip.zip", ppath + "/dir1/dir2/test2.bmp", false, "dir1/dir2/test2.bmp");
        plog("compress: " + zres.ToString());


        //append a file to it
        zres = lzip.compress_File(9, ppath + "/test2Zip.zip", ppath + "/dir1/dir2/dir3/Unity_1.jpg", true, "dir1/dir2/dir3/Unity_1.jpg");
        plog("append: " + zres.ToString());



        plog("");
        //compress multiple files added in some lists, and protect them with a password (disabled for WSA due to certification reasons)
        //
                #if !UNITY_WSA || UNITY_EDITOR
        //create a list of files to get compressed
        List <string> myFiles = new List <string>();
        myFiles.Add(ppath + "/test22P.bmp");
        myFiles.Add(ppath + "/dir1/dir2/test2.bmp");
        //create an optional list with new names for the above listings
        List <string> myNames = new List <string>();
        myNames.Add("NEW_test22P.bmp");
        myNames.Add("dir13/dir23/New_test2.bmp");
        //use password and bz2 method
        zres = lzip.compress_File_List(9, ppath + "/newTestZip.zip", myFiles.ToArray(), progress, false, myNames.ToArray(), "password");
        plog("MultiFile Compress password: "******"/newTestZip.zip", ppath + "/", progress, null, progress2, "password");
        plog("decompress password: "******"");
                #endif


        //compress a buffer to a file and name it.
        plog("Buffer2File: " + lzip.buffer2File(9, ppath + "/test3Zip.zip", "buffer.bin", reusableBuffer).ToString());



        //compress a buffer, name it and append it to an existing zip archive
        plog("Buffer2File append: " + lzip.buffer2File(9, ppath + "/test3Zip.zip", "dir4/buffer.bin", reusableBuffer, true).ToString());
        // Debug.Log(reusableBuffer.Length);
        plog("");


        //get the uncompressed size of a specific file in the zip archive
        plog("get entry size: " + lzip.getEntrySize(ppath + "/testZip.zip", "dir1/dir2/test2.bmp").ToString());
        plog("");


        //extract a file in a zip archive to a byte buffer (referenced buffer method)
        plog("entry2Buffer1: " + lzip.entry2Buffer(ppath + "/testZip.zip", "dir1/dir2/test2.bmp", ref reusableBuffer2).ToString());
        // File.WriteAllBytes(ppath + "/out.bmp", reusableBuffer2);
        plog("");

        //extract an entry in a zip archive to a fixed size buffer
        plog("entry2FixedBuffer: " + lzip.entry2FixedBuffer(ppath + "/testZip.zip", "dir1/dir2/test2.bmp", ref fixedBuffer).ToString());
        plog("");


        //GZIP TESTS---------------------------------------------------------------------------------------------------------------

        //create a buffer that will store the compressed gzip data.
        //it should be at least the size of the input buffer +18 bytes.
        var btt = new byte[reusableBuffer2.Length + 18];

        //compress a buffer to gzip format and add gzip header and footer
        //returns total size of compressed buffer.
        int rr = lzip.gzip(reusableBuffer2, btt, 9, true, true);
        plog("gzip compressed size: " + rr);


        //create a buffer to store the compressed data (optional, if you want to write out a gzip file)
        var bt2 = new byte[rr];
        //copy the data to the new buffer
        Buffer.BlockCopy(btt, 0, bt2, 0, rr);

        //write a .gz file
        File.WriteAllBytes(ppath + "/test2.bmp.gz", bt2);

        //create a buffer to decompress a gzip buffer
        var bt3 = new byte[lzip.gzipUncompressedSize(bt2)];

        //decompress the gzip compressed buffer
        int gzres = lzip.unGzip(bt2, bt3);

        if (gzres > 0)
        {
            File.WriteAllBytes(ppath + "/test2GZIP.bmp", bt3); plog("gzip decompression: success " + gzres.ToString());
        }
        else
        {
            plog("gzip decompression error: " + gzres.ToString());
        }

        btt = null; bt2 = null; bt3 = null;
        plog("");
        //END GZIP TESTS-----------------------------------------------------------------------------------------------------------


        //extract a file in a zip archive to a byte buffer (new buffer method)
        var newBuffer = lzip.entry2Buffer(ppath + "/testZip.zip", "dir1/dir2/test2.bmp");
        zres = 0;
        if (newBuffer != null)
        {
            zres = 1;
        }
        plog("entry2Buffer2: " + zres.ToString());
        // write a file out to confirm all was ok
        //File.WriteAllBytes(ppath + "/out.bmp", newBuffer);
        plog("");


        //FIXED BUFFER FUNCTIONS:
        int compressedSize = lzip.compressBufferFixed(newBuffer, ref fixedInBuffer, 9);
        plog(" # Compress Fixed size Buffer: " + compressedSize.ToString());

        if (compressedSize > 0)
        {
            int decommpressedSize = lzip.decompressBufferFixed(fixedInBuffer, ref fixedOutBuffer);
            if (decommpressedSize > 0)
            {
                plog(" # Decompress Fixed size Buffer: " + decommpressedSize.ToString());
            }
        }
        plog("");


        //compress a buffer into a referenced buffer
        pass = lzip.compressBuffer(reusableBuffer2, ref reusableBuffer3, 9);
        plog("compressBuffer1: " + pass.ToString());
        // write a file out to confirm all was ok
        //File.WriteAllBytes(ppath + "/out.bin", reusableBuffer3);


        //compress a buffer and return a new buffer with the compresed data.
        newBuffer = lzip.compressBuffer(reusableBuffer2, 9);
        zres      = 0;
        if (newBuffer != null)
        {
            zres = 1;
        }
        plog("compressBuffer2: " + zres.ToString());
        plog("");


        //decompress a previously compressed buffer into a referenced buffer
        pass = lzip.decompressBuffer(reusableBuffer3, ref reusableBuffer2);
        plog("decompressBuffer1: " + pass.ToString());
        //Debug.Log(reusableBuffer2.Length);
        // write a file out to confirm all was ok
        //File.WriteAllBytes(ppath + "/out.bmp", reusableBuffer2);
        zres = 0;
        if (newBuffer != null)
        {
            zres = 1;
        }


        //decompress a previously compressed buffer into a new returned buffer
        newBuffer = lzip.decompressBuffer(reusableBuffer3);
        plog("decompressBuffer2: " + zres.ToString());
        plog("");


        //get file info of the zip file (names, uncompressed and compressed sizes)
        plog("total bytes: " + lzip.getFileInfo(ppath + "/testZip.zip").ToString());



        //Look through the ninfo, uinfo and cinfo Lists where the file names and sizes are stored.
        if (lzip.ninfo != null)
        {
            for (int i = 0; i < lzip.ninfo.Count; i++)
            {
                log += lzip.ninfo[i] + " - " + lzip.uinfo[i] + " / " + lzip.cinfo[i] + "\n";
            }
        }
        plog("");


                #if !(UNITY_WSA_8_1 || UNITY_WP_8_1 || UNITY_WINRT_8_1) || UNITY_EDITOR
        //Until a replacement function is made for 'Directory.GetFiles' on WSA8.1 this function is disabled for it.
        //Recursively compress a directory
        lzip.compressDir(ppath + "/dir1", 9, ppath + "/recursive.zip", false, null);
        plog("recursive - no. of files: " + lzip.cProgress.ToString());


        //decompress the above compressed zip to make sure all was ok.
        zres = lzip.decompress_File(ppath + "/recursive.zip", ppath + "/recursive/", progress, null, progress2);
        plog("decompress recursive: " + zres.ToString());
                #endif

        //multithreading example to show progress of extraction, using the ref progress int
        //in this example it happens to fast, because I didn't want the user to download a big file with many entrie.
                #if !NETFX_CORE
        Thread th = new Thread(decompressFunc); th.Start();
                #endif
                #if NETFX_CORE && UNITY_WSA_10_0
        Task task = new Task(new Action(decompressFunc)); task.Start();
                #endif

        //delete/replace entry example
        if (File.Exists(ppath + "/test-Zip.zip"))
        {
            File.Delete(ppath + "/test-Zip.zip");
        }
                #if UNITY_WSA && !UNITY_EDITOR
        if (File.Exists(ppath + "/testZip.zip"))
        {
            lzip.fileCopy(ppath + "/testZip.zip", ppath + "/test-Zip.zip");
        }
                #else
        if (File.Exists(ppath + "/testZip.zip"))
        {
            File.Copy(ppath + "/testZip.zip", ppath + "/test-Zip.zip");
        }
                #endif


        //replace an entry with a byte buffer
        var newBuffer3 = lzip.entry2Buffer(ppath + "/testZip.zip", "dir1/dir2/test2.bmp");
        plog("replace entry: " + lzip.replace_entry(ppath + "/test-Zip.zip", "dir1/dir2/test2.bmp", newBuffer3, 9, null).ToString());


        //replace an entry with a file in the disk (ability to asign a password or bz2 compression)
        plog("replace entry 2: " + lzip.replace_entry(ppath + "/test-Zip.zip", "dir1/dir2/test2.bmp", ppath + "/dir1/dir2/test2.bmp", 9, null, null).ToString());


        //delete an entry in the zip
        plog("delete entry: " + lzip.delete_entry(ppath + "/test-Zip.zip", "dir1/dir2/test2.bmp").ToString());
    }
Ejemplo n.º 10
0
    IEnumerator LoadDataFiles()
    {
        Debug.Log("LoadDataFiles");

        string path = Application.persistentDataPath + "/" + guideZipId + "/data.json";


        if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            path = "file:///" + path;
        }

        if (Application.platform == RuntimePlatform.WindowsPlayer)
        {
            path = "file://" + path;
        }

        if (Application.platform == RuntimePlatform.WSAPlayerX64)
        {
            path = "file://" + path;
        }

        if (Application.platform == RuntimePlatform.Android)
        {
            path = "file://" + path;
        }

        //Debug.Log("JSON file path: " + path);
        debugText.text += "\n" + path;
        WWW dataWWW = new WWW(path);

        // Debug.Log("loading path: " + path);

        yield return(dataWWW);

        //Debug.Log("LoadDataFileFile dataWWW.error: " + dataWWW.error);
        if (string.IsNullOrEmpty(dataWWW.error))
        {
            string jsonData = dataWWW.text;
            jsonData = jsonData.Replace("%20", " ");
            jsonData = jsonData.Replace("~/files", "/files");
            //jsonData = jsonData.Replace("\"", "");
            jsonData = jsonData.Replace("&lt;", "<");
            jsonData = jsonData.Replace("&gt;", ">");


            guide = new Guide();
            guide = JsonUtility.FromJson <Guide>(jsonData);

            Debug.Log("jsonData: " + jsonData);
            navigation.activateFirstScreen();

            guide.TranslatedContents[0].TagCategories[1].Tags = guide.TranslatedContents[0].TagCategories[1].Tags.OrderBy(x => int.Parse(x.Title)).ToArray();

            /*
             * for(int  i= 0; i < guide.TranslatedContents[0].TagCategories[1].Tags.Length; i++)
             * {
             *  Debug.Log(guide.TranslatedContents[0].TagCategories[1].Tags[i].Title);
             * }
             */
            mainScreenController.CreateMenus(guide.TranslatedContents[0].TagCategories);
            mainScreenController.SetThemes(guide.TranslatedContents[0].Themes);

            if (File.Exists(ppath + "/" + zipFile))
            {
                File.Delete(ppath + "/" + zipFile);
            }


            hidePreloadScreen();
        }
        else
        {
            Debug.Log("ERROR: " + dataWWW.error);
        }
    }
Ejemplo n.º 11
0
    public static List <long> sinfo   = new List <long>();   //file sizes

    //this function fills the ArrayLists with the filenames and file sizes that are in the 7zip file
    //returns			: the total size in bytes of the files in the 7z archive
    //
    //filePath			: the full path to the archive, including the archives name. (/myPath/myArchive.7z)
    //tempPath			: (optional) a temp path that will be used to write the files info (otherwise the path of the 7z archive will be used)
    //					: this is useful when your 7z archive resides in a read only location.
    //					: the tempPath should be in this form: 'dir/dir/myTempLog' with no slash in the end. The last name will be used as the log's filename.
    //FileBuffer		: A buffer that holds a 7zip file. When assigned the function will read from this buffer and will ignore the filePath. (Linux, iOS, Android, MacOSX)
    //
    //trueTotalFiles is an integer variable to store the total number of files in a 7z archive, excluding the folders.
    public static long get7zInfo(string filePath, string tempPath = null, byte[] FileBuffer = null)
    {
        ninfo.Clear(); sinfo.Clear();
        trueTotalFiles = 0;
        int    res     = -1;
        string logPath = "";

                #if !NETFX_CORE
        if (@tempPath == null)
        {
            if (persitentDataPath.Length > 0)
            {
                logPath = @persitentDataPath + "/sevenZip.log";
            }
            else
            {
                logPath = @Application.persistentDataPath + "/sevenZip.log";
            }
        }
        else
        {
            logPath = @tempPath;
        }
                #endif
        //for WSA, logPath should always be: Application.persistentDataPath + "/sevenZip.log";
                #if NETFX_CORE
                        #if UNITY_WSA_10_0
        if (persitentDataPath.Length > 0)
        {
            logPath = @persitentDataPath + "/sevenZip.log";
        }
        else
        {
            logPath = @Application.persistentDataPath + "/sevenZip.log";
        }
                        #endif
                        #if UNITY_WSA_8_1 || UNITY_WP_8_1 || UNITY_WINRT_8_1
        if (persitentDataPath.Length > 0)
        {
            logPath = @persitentDataPath + "/sevenZip.log";
        }
        else
        {
            logPath = @UnityEngine.Windows.Directory.localFolder + "/sevenZip.log";
        }
                        #endif
                #endif

        if (File.Exists(logPath + ".txt"))
        {
            File.Delete(logPath + ".txt");
        }

                #if (UNITY_IPHONE || UNITY_IOS || UNITY_STANDALONE_OSX || UNITY_ANDROID || UNITY_STANDALONE_LINUX || UNITY_EDITOR) && !UNITY_EDITOR_WIN
        if (FileBuffer != null)
        {
            GCHandle fbuf = GCHandle.Alloc(FileBuffer, GCHandleType.Pinned);
            res = _getSize(null, logPath, fbuf.AddrOfPinnedObject(), FileBuffer.Length);
            fbuf.Free();
        }
        else
        {
            res = _getSize(@filePath, logPath, IntPtr.Zero, 0);
        }
        #else
        res = _getSize(@filePath, logPath, IntPtr.Zero, 0);
        #endif

        if (res == -1) /*Debug.Log("Input file not found.");*/ return {
            (-1);
        }

        if (!File.Exists(logPath + ".txt")) /* Debug.Log("Info file not found.");*/ return {
            (-3);
        }

                #if !NETFX_CORE
        StreamReader r = new StreamReader(logPath + ".txt");
                #endif
                #if NETFX_CORE
                        #if UNITY_WSA_10_0
        IsolatedStorageFile ipath = IsolatedStorageFile.GetUserStoreForApplication();
        StreamReader        r     = new StreamReader(new IsolatedStorageFileStream("sevenZip.log.txt", FileMode.Open, ipath));
                        #endif
                        #if UNITY_WSA_8_1 || UNITY_WP_8_1 || UNITY_WINRT_8_1
        var          data = UnityEngine.Windows.File.ReadAllBytes(logPath + ".txt");
        string       ss   = System.Text.Encoding.UTF8.GetString(data, 0, data.Length);
        StringReader r    = new StringReader(ss);
                        #endif
                #endif

        string   line;
        string[] rtt;
        long     t = 0, sum = 0;

        while ((line = r.ReadLine()) != null)
        {
            rtt = line.Split('|');
            ninfo.Add(rtt[0]);
            long.TryParse(rtt[1], out t);
            sum += t;
            sinfo.Add(t);
            if (t > 0)
            {
                trueTotalFiles++;
            }
        }

                #if !NETFX_CORE
        r.Close();
                #endif
        r.Dispose();
        File.Delete(logPath + ".txt");

        return(sum);
    }
Ejemplo n.º 12
0
    void OnGUI()
    {
        if (downloadDone == true)
        {
            GUI.Label(new Rect(50, 0, 350, 30), "package downloaded, ready to extract");
            GUI.Label(new Rect(50, 30, 450, 40), ppath);

            //when we call the decompress of 7z archives function, show a referenced integer that indicate the current file beeing extracted.
                        #if (!UNITY_WSA_8_1 && !UNITY_WP_8_1 && !UNITY_WINRT_8_1) || UNITY_EDITOR
                                #if !NETFX_CORE
            if (th != null)
            {
                GUI.Label(new Rect(Screen.width - 90, 10, 90, 50), progress[0].ToString());
            }
                                #endif
                                #if NETFX_CORE && UNITY_WSA_10_0
            if (task != null)
            {
                GUI.Label(new Rect(Screen.width - 90, 10, 90, 50), progress[0].ToString());
            }
                                #endif
                        #endif

            GUI.Label(new Rect(50, 70, 400, 30), "decompress Buffer: " + pass1.ToString());
            GUI.TextArea(new Rect(50, 290, 640, 140), tsize.ToString() + "\n" + log);

            #if !(UNITY_WSA || UNITY_WSA_8_1 || UNITY_WP_8_1 || UNITY_WINRT_8_1) || UNITY_EDITOR
            GUI.Label(new Rect(50, 100, 400, 30), "compress Buffer  : " + pass2.ToString());
                        #endif
            if (GUI.Button(new Rect(50, 150, 250, 50), "start 7z test"))
            {
                //delete the known files that are extracted from the downloaded example z file
                //it is important to do this when you re-extract the same files  on some platforms.
                if (File.Exists(ppath + "/1.txt"))
                {
                    File.Delete(ppath + "/1.txt");
                }
                if (File.Exists(ppath + "/2.txt"))
                {
                    File.Delete(ppath + "/2.txt");
                }
                log = "";
                compressionStarted = true;
                //call the decompresion demo functions.
                DoDecompression();
            }

            //decompress file from buffer
                        #if (UNITY_IPHONE || UNITY_IOS || UNITY_STANDALONE_OSX || UNITY_ANDROID || UNITY_STANDALONE_LINUX || UNITY_EDITOR) && !UNITY_EDITOR_WIN
            if (GUI.Button(new Rect(320, 150, 250, 50), "File Buffer test"))
            {
                doFileBufferTest();
            }
                        #endif
        }

        if (compressionStarted)
        {
            //if the return code is 1 then the decompression was succesful.
            GUI.Label(new Rect(50, 210, 250, 40), "7z return code: " + lzres.ToString());
            //time took to decompress
            GUI.Label(new Rect(50, 250, 250, 50), "time: " + t1.ToString());

                        #if !(UNITY_WSA_8_1 || UNITY_WP_8_1 || UNITY_WINRT_8_1) || UNITY_EDITOR
            if (lzres2 != 0)
            {
                GUI.Label(new Rect(50, 450, 250, 30), "lzma encoded " + lzres2.ToString());
            }
            if (lzres3 != 0)
            {
                GUI.Label(new Rect(50, 480, 250, 30), "lzma decoded " + lzres3.ToString());
            }
                        #endif

            if (lzres4 > 0)
            {
                GUI.Label(new Rect(50, 510, 250, 30), "decoded to buffer: ok");
            }
        }
    }
Ejemplo n.º 13
0
    //call from separate thread. here you can get the progress of the extracted files through a referenced integer.
    IEnumerator decompressFunc()
    {
        //decompress 7zip
        log  += "<color=white>decompressing 7zip ...\n</color>";
        t1    = Time.realtimeSinceStartup;
        lzres = lzma.doDecompress7zip(ppath + "/" + myFile, ppath + "/", true, true);
        tim   = Time.realtimeSinceStartup - t1;
        log  += "<color=white>status: " + lzres + " |  7z time: " + tim + " sec\n\n</color>";
                #if !UNITY_WSA && !NETFX_CORE || UNITY_EDITOR
        log += "<color=grey>compressing lzma ...\n</color>";
                #else
        log += "<color=grey>compressing zip ...\n</color>";
                #endif
        yield return(true);

        //compress lzma alone
                #if !UNITY_WSA && !NETFX_CORE || UNITY_EDITOR
        t1 = Time.realtimeSinceStartup;
        lzma.setProps(9);
        if (File.Exists(ppath + "/" + uncFile + ".lzma"))
        {
            File.Delete(ppath + "/" + uncFile + ".lzma");
        }
        lzres = lzma.LzmaUtilEncode(ppath + "/" + uncFile, ppath + "/" + uncFile + ".lzma");
        tim   = Time.realtimeSinceStartup - t1;
        log  += "<color=grey>status: " + lzres + " |  lzma time: " + tim + " sec\n\n</color>";
        log  += "<color=grey>compressing zip ...\n</color>";
        yield return(true);
                #endif

        //compress zip
        t1 = Time.realtimeSinceStartup;
        if (File.Exists(ppath + "/" + myFile2))
        {
            File.Delete(ppath + "/" + myFile2);
        }
        zipres = lzip.compress_File(9, ppath + "/" + myFile2, ppath + "/" + uncFile);
        tim    = Time.realtimeSinceStartup - t1;
        log   += "<color=grey>status: " + zipres + " |  zip time: " + tim + " sec\n\n</color>";
        log   += "<color=white>decompressing zip ...\n</color>";
        yield return(true);

        //decompress zip
        t1     = Time.realtimeSinceStartup;
        zipres = lzip.decompress_File(ppath + "/" + myFile2, ppath + "/", progress, null, progress1);
        tim    = Time.realtimeSinceStartup - t1;
        log   += "<color=white>status: " + zipres + " |  zip time: " + tim + " sec\n\n</color>";
        log   += "<color=grey>Compressing to flz ...\n</color>";
        yield return(true);

        //compress flz
        t1     = Time.realtimeSinceStartup;
        flzres = fLZ.compressFile(ppath + "/" + uncFile, ppath + "/" + uncFile + ".flz", 2, true, progress2);
        tim    = Time.realtimeSinceStartup - t1;
        log   += "<color=grey>status: " + flzres + " |  flz time: </color><color=orange>" + tim + " sec\n\n</color>";
        log   += "<color=white>Decompressing flz ...\n</color>";
        yield return(true);

        //decompress flz
        t1     = Time.realtimeSinceStartup;
        flzres = fLZ.decompressFile(ppath + "/" + uncFile + ".flz", ppath + "/" + uncFile, true, progress2);
        tim    = Time.realtimeSinceStartup - t1;
        log   += "<color=white>status: " + flzres + " |  flz time: " + tim + " sec\n\n</color>";
        log   += "<color=grey>Compressing to LZ4 ...\n</color>";
        yield return(true);

        //compress lz4
        t1     = Time.realtimeSinceStartup;
        lz4res = (int)LZ4.compress(ppath + "/" + uncFile, ppath + "/" + uncFile + ".lz4", 9, progress3);
        tim    = Time.realtimeSinceStartup - t1;
        log   += "<color=grey>status: " + lz4res + " |  LZ4 time: " + tim + " sec\n\n</color>";
        log   += "<color=white>Decompressing LZ4 ...\n</color>";
        yield return(true);

        //decompress lz4
        t1     = Time.realtimeSinceStartup;
        lz4res = LZ4.decompress(ppath + "/" + uncFile + ".lz4", ppath + "/" + uncFile, bytes);
        tim    = Time.realtimeSinceStartup - t1;
        log   += "<color=white>status: " + lz4res + " |  LZ4 time: </color><color=lime>" + tim + " sec\n\n</color>";
        log   += "<color=grey>Compressing to brotli ...\n</color>";
        yield return(true);

        //compress brotli
        t1    = Time.realtimeSinceStartup;
        brres = (int)brotli.compressFile(ppath + "/" + uncFile, ppath + "/" + uncFile + ".br", progress4);
        tim   = Time.realtimeSinceStartup - t1;
        log  += "<color=grey>status: " + brres + " |  brotli time: " + tim + " sec\n\n</color>";
        log  += "<color=white>Decompressing brotli ...\n</color>";
        yield return(true);

        //decompress brotli
        t1    = Time.realtimeSinceStartup;
        brres = brotli.decompressFile(ppath + "/" + uncFile + ".br", ppath + "/" + uncFile, progress4);
        tim   = Time.realtimeSinceStartup - t1;
        log  += "<color=white>status: " + brres + " |  brotli time: </color><color=lime>" + tim + " sec\n\n</color>";
        yield return(true);

        //test setting file permissions
        Debug.Log(lzma.setFilePermissions(ppath + "/" + uncFile, "rw", "r", "r"));
        Debug.Log(lzip.setFilePermissions(ppath + "/" + uncFile, "rw", "r", "r"));
        Debug.Log(fLZ.setFilePermissions(ppath + "/" + uncFile, "rw", "r", "r"));
        Debug.Log(LZ4.setFilePermissions(ppath + "/" + uncFile, "rw", "r", "r"));
        Debug.Log(brotli.setFilePermissions(ppath + "/" + uncFile, "rw", "r", "r"));

        benchmarkStarted = false;
    }
    private void OnGUI()
    {
        #region ScrollView
        scrollPosition = GUILayout.BeginScrollView(scrollPosition);
        GUILayout.Space(space);

        if (GUILayout.Button("Create new level", GUILayout.Height(buttonHeight), GUILayout.Width(buttonWidth)))
        {
            newSceneIndex = FindAppropriateIndex();

            if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
            {
                // Create new scene
                EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);

                // Add new scene to build settings
                AddNewSceneToBuildSetting(newSceneIndex);

                // Add prefabs to new scene
                AddPrefabsToNewScene();

                // Add background to new scene
                AddBackgroundToNewScene();

                // Save scene after adding everything
                SaveScene();
            }
            return;
        }

        GUILayout.Space(space);

        GUILayout.BeginHorizontal();
        GUILayout.Label("Frame type", GUILayout.Width(labelWidth));
        // Popup (it's a dropdown)
        popupIndex = EditorGUILayout.Popup(popupIndex, levelEditorSO.frameType, GUILayout.Height(dropdownHeight), GUILayout.Width(dropdownWidth));
        GUILayout.EndHorizontal();

        GUILayout.Space(space);

        GUILayout.BeginHorizontal();
        GUILayout.Label("Scene Folder", GUILayout.Width(labelWidth));
        GUI.SetNextControlName("dropdownFolderName");
        folderIndex = EditorGUILayout.Popup(folderIndex, levelEditorSO.sceneFolderName, GUILayout.Height(dropdownHeight), GUILayout.Width(dropdownWidth));
        GUILayout.EndHorizontal();

        GUI.enabled = true;

        #region Edit existing level


        #region Textfield && Arrows
        EditorGUILayout.BeginHorizontal();
        GUIStyle gUIStyleButton = new GUIStyle(GUI.skin.button);
        gUIStyleButton.fontSize = 20;

        // Left arrow
        if (GUILayout.Button("↤", gUIStyleButton, GUILayout.Height(buttonHeight), GUILayout.Width(50)))
        {
            int newNumber = (int.Parse(textFieldNumber) - 1);
            if (newNumber >= 1)
            {
                textFieldNumber = newNumber.ToString();
                //ShowYesNoPopup();
                ChangeImage();
                GUI.FocusControl("dropdownFolderName");
            }
        }

        // Textfield
        GUIStyle gUIStyle = new GUIStyle(GUI.skin.textField);
        gUIStyle.alignment = TextAnchor.MiddleLeft;
        textFieldNumber    = EditorGUILayout.TextField(textFieldNumber, gUIStyle, GUILayout.Height(buttonHeight), GUILayout.Width(100));

        // Right arrow
        if (GUILayout.Button("↦", gUIStyleButton, GUILayout.Height(buttonHeight), GUILayout.Width(50)))
        {
            int newNumber = (int.Parse(textFieldNumber) + 1);
            textFieldNumber = newNumber.ToString();
            //ShowYesNoPopup();
            ChangeImage();
            GUI.FocusControl("dropdownFolderName");
        }
        EditorGUILayout.EndHorizontal();
        #endregion

        GUILayout.Space(space / 2);


        if (GUILayout.Button($"Open Level {textFieldNumber}", GUILayout.Height(buttonHeight), GUILayout.Width(buttonWidth)))
        {
            if (int.TryParse(textFieldNumber, out int i))
            {
                ShowUnSavePopup();
                ChangeImage();
            }
        }
        deleteScene = EditorGUILayout.BeginToggleGroup("Delete current scene", deleteScene);
        GUILayout.Space(space / 2);
        if (GUILayout.Button("Delete", GUILayout.Height(buttonHeight), GUILayout.Width(buttonWidth)))
        {
            string sceneName = EditorSceneManager.GetActiveScene().name;
            string filePath  = $"Assets/_Main/_Scenes/{levelEditorSO.sceneFolderName[folderIndex]}/{sceneName}.unity";
            if (File.Exists(filePath))
            {
                if (EditorUtility.DisplayDialog($"Delete Level{textFieldNumber} scene", $"Do you want to delete {sceneName} scene?", "Yes", "No"))
                {
                    File.Delete(filePath);
#if UNITY_EDITOR
                    AssetDatabase.Refresh();
                    UpdateSceneAmountInScriptableObject(false);
#endif

                    EditorBuildSettingsScene[] originalSettingScenes = EditorBuildSettings.scenes;
                    EditorBuildSettingsScene   sceneToRemove         = new EditorBuildSettingsScene($"Assets/_Main/_Scenes/{levelEditorSO.sceneFolderName[folderIndex]}/{sceneName}.unity", true);
                    EditorBuildSettingsScene[] newSettings           = new EditorBuildSettingsScene[originalSettingScenes.Length - 1];
                    for (int i = 0, j = 0; i < originalSettingScenes.Length; i++)
                    {
                        if (originalSettingScenes[i].path != sceneToRemove.path)
                        {
                            newSettings[j++] = originalSettingScenes[i];
                        }
                    }
                    EditorBuildSettings.scenes = newSettings;

                    EditorSceneManager.OpenScene(EditorBuildSettings.scenes[EditorBuildSettings.scenes.Length - 1].path);

                    EditorUtility.DisplayDialog("Message", $"{sceneName} has been deleted from project folder and build settings", "OK");
                }
            }
            else
            {
                EditorUtility.DisplayDialog("File not found", $"Can not find IntroScene in folder {filePath}", "OK");
            }
        }
        EditorGUILayout.EndToggleGroup();
        #endregion

        #region Intro, Menu, Menu Select Scene
        int minus = 30;
        GUILayout.Space(space);
        GUILayout.BeginHorizontal();
        if (GUILayout.Button($"Open {levelEditorSO.sceneFolderName[folderIndex]} Select Level", GUILayout.Width(buttonWidth - minus), GUILayout.Height(buttonHeight)))
        {
            if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
            {
                try
                {
                    EditorSceneManager.OpenScene($"Assets/_Main/_Scenes/{levelEditorSO.sceneFolderName[folderIndex]}/MenuSelectLevel{folderIndex + 1}.unity");
                }
                catch (Exception)
                {
                    EditorUtility.DisplayDialog("File not found", $"Can not find MenuSelectLevel{folderIndex + 1} in folder Assets/_Main/_Scenes/{levelEditorSO.sceneFolderName[folderIndex]}", "OK");
                }
            }
        }

        if (GUILayout.Button("Open Intro Scene", GUILayout.Width(buttonWidth - minus), GUILayout.Height(buttonHeight)))
        {
            if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
            {
                try
                {
                    EditorSceneManager.OpenScene("Assets/_Main/_Scenes/IntroScene.unity");
                }
                catch (Exception)
                {
                    EditorUtility.DisplayDialog("File not found", "Can not find IntroScene in folder Assets/_Main/_Scenes/", "OK");
                }
            }
        }
        GUILayout.EndHorizontal();

        GUILayout.Space(space);
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Open Menu Scene", GUILayout.Width(buttonWidth - minus), GUILayout.Height(buttonHeight)))
        {
            if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
            {
                try
                {
                    EditorSceneManager.OpenScene("Assets/_Main/_Scenes/MenuScene.unity");
                }
                catch (Exception)
                {
                    EditorUtility.DisplayDialog("File not found", "Can not find MenuScene in folder Assets/_Main/_Scenes/", "OK");
                }
            }
        }

        if (GUILayout.Button("Open Menu Select Episode", GUILayout.Width(buttonWidth - minus), GUILayout.Height(buttonHeight)))
        {
            if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
            {
                try
                {
                    EditorSceneManager.OpenScene("Assets/_Main/_Scenes/MenuSelectEpisode.unity");
                }
                catch (Exception)
                {
                    EditorUtility.DisplayDialog("File not found", "Can not find MenuSelectEpisode in folder Assets/_Main/_Scenes/", "OK");
                }
            }
        }
        GUILayout.EndHorizontal();
        #endregion

        #region Scene Image
        GUI.enabled = true;
        GUILayout.Space(space / 2);
        if (!imageExist)
        {
            GUILayout.Label("Image does not exists in folder");
        }
        else
        {
            GUILayout.Label(imageOfLevel, GUILayout.Width(Screen.width - 25));
        }
        #endregion

        GUILayout.EndScrollView();
        #endregion end ScrollView
    }