// Update is called once per frame void Update () { if(AlreadyInstalled==false){ DirectoryInfo directoryInfo = new DirectoryInfo (Application.persistentDataPath + "/"); //print ("Streaming Assets Path: " + directoryInfo); FileInfo[] allFiles = directoryInfo.GetFiles ("*.demoidlevel"); foreach (FileInfo file in allFiles) { if (isrunning == false) { StartCoroutine (DetectNotInstalledLevels ()); } } if (Directory.Exists (Application.persistentDataPath + "/Inbox/")) { foreach (var file in Directory.GetFiles(Application.persistentDataPath + "/Inbox/", "*.demoidlevel")) { var toPath = Application.persistentDataPath + "/Inbox/" + Path.GetFileName (file); print (toPath); if (File.Exists (toPath)) { if (isrunning == false) { StartCoroutine (DetectNotInstalledLevels ()); } } } } } }
// Use this for initialization void Start() { #if (UNITY_WSA_8_1 || UNITY_WP_8_1 || UNITY_WINRT_8_1) && !UNITY_EDITOR ppath = UnityEngine.Windows.Directory.localFolder; #else ppath = Application.persistentDataPath; #endif #if UNITY_STANDALONE_OSX && !UNITY_EDITOR ppath = "."; #endif buff = new byte[0]; Debug.Log(ppath); Screen.sleepTimeout = SleepTimeout.NeverSleep; if (!File.Exists(ppath + "/" + myFile)) { StartCoroutine(DownloadTestFile()); } else { downloadDone = true; } }
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; }
/// <summary> /// SVN의 경로를 자동으로 탐색합니다. 찾는데 실패한경우 null리턴 /// </summary> /// <returns> null : cannot found. </returns> public static string FindSvnPathAuto() { List <string> pathList = new List <string>() { @"{Drive}:\Program Files\TortoiseSVN\bin\TortoiseProc.exe", @"{Drive}:\Program Files (x86)\TortoiseSVN\bin\TortoiseProc.exe", @"{Drive}:\TortoiseSVN\bin\TortoiseProc.exe", @"{Drive}:\TortoiseSVN\bin\TortoiseProc.exe" }; List <string> makeRealPathList = new List <string>(); for (int i = 0; i < pathList.Count; i++) { for (int j = 65; j < 90; j++) { var tryPath = pathList[i].Replace("{Drive}", ((char)j).ToString()); if (File.Exists(tryPath)) { Debug.Log("SVN.exe Auto Found! " + tryPath); return(tryPath); } } } return(null); }
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; }
// ============================================================================================================================================================= IEnumerator DownloadZipFile() { Debug.Log("starting download"); myFile = "testZip.zip"; //make sure a previous zip file having the same name with the one we want to download does not exist in the ppath folder if (File.Exists(ppath + "/" + myFile)) { downloadDone = true; yield break; } //File.Delete(ppath + "/" + myFile); //replace the link to the zip file with your own (although this will work also) www = new WWW("https://dl.dropboxusercontent.com/s/xve34ldz3pqvmh1/" + myFile); yield return(www); if (www.error != null) { Debug.Log(www.error); } downloadDone = true; //write the downloaded zip 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; }
IEnumerator DoTestsWebGL() { yield return(true); //File tests //compress a file to lz4 with highest level of compression (9). lz1 = LZ4.compress(ppath + "/" + myFile, ppath + "/" + myFile + ".lz4", 9, progress); //decompress the previously compressed archive lz2 = LZ4.decompress(ppath + "/" + myFile + ".lz4", ppath + "/" + myFile + "B.tif", bytes); //Buffer tests if (File.Exists(ppath + "/" + myFile)) { byte[] bt = File.ReadAllBytes(ppath + "/" + myFile); //compress a byte buffer (we write the output buffer to a file for debug purposes.) if (LZ4.compressBuffer(bt, ref buff, 9, true)) { lz3 = 1; File.WriteAllBytes(ppath + "/buffer1.lz4buf", buff); } byte[] bt2 = File.ReadAllBytes(ppath + "/buffer1.lz4buf"); //decompress a byte buffer (we write the output buffer to a file for debug purposes.) if (LZ4.decompressBuffer(bt2, ref buff, true)) { lz4 = 1; File.WriteAllBytes(ppath + "/buffer1.tif", buff); } bt2 = null; bt = null; } }
//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)); }
void Start() { ppath = Application.persistentDataPath; // //we are setting the lzma.persitentDataPath so the get7zinfo, get7zSize, decode2Buffer functions can work on separate threads! //on WSA it must be 'Application.persistentDataPath' ! lzma.persitentDataPath = Application.persistentDataPath; // #if UNITY_STANDALONE_OSX && !UNITY_EDITOR ppath = "."; #endif Screen.sleepTimeout = SleepTimeout.NeverSleep; if (!File.Exists(ppath + "/" + myFile)) { StartCoroutine(Download7ZFile()); } else { downloadDone = true; } benchmarkStarted = false; style = new GUIStyle(); style.richText = true; GUI.color = Color.black; }
IEnumerator DoTestsWSA81() { yield return(true); //File tests //compress a file to brotli format. lz1 = brotli.compressFile(ppath + "/" + myFile, ppath + "/" + myFile + ".br", progress); //decompress the previously compressed archive lz2 = brotli.decompressFile(ppath + "/" + myFile + ".br", ppath + "/" + myFile + "Br.tif", progress2); //Buffer tests if (File.Exists(ppath + "/" + myFile)) { byte[] bt = File.ReadAllBytes(ppath + "/" + myFile); //compress a byte buffer (we write the output buffer to a file for debug purposes.) if (brotli.compressBuffer(bt, ref buff, progress3)) { lz3 = 1; File.WriteAllBytes(ppath + "/buffer1.brbuf", buff); } byte[] bt2 = File.ReadAllBytes(ppath + "/buffer1.brbuf"); //decompress a byte buffer (we write the output buffer to a file for debug purposes.) if (brotli.decompressBuffer(bt2, ref buff)) { lz4 = 1; File.WriteAllBytes(ppath + "/buffer1.tif", buff); } bt2 = null; bt = null; } }
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; }
IEnumerator DoTestsWSA81() { yield return(true); //File tests //compress a file to flz with highest level of compression (2). lz1 = fLZ.compressFile(ppath + "/" + myFile, ppath + "/" + myFile + ".flz", 2, true, progress); //decompress the previously compressed archive lz2 = fLZ.decompressFile(ppath + "/" + myFile + ".flz", ppath + "/" + myFile + "B.tif", true, progress2); //Buffer tests if (File.Exists(ppath + "/" + myFile)) { byte[] bt = File.ReadAllBytes(ppath + "/" + myFile); //compress a byte buffer (we write the output buffer to a file for debug purposes.) if (fLZ.compressBuffer(bt, ref buff, 2, true)) { lz3 = 1; File.WriteAllBytes(ppath + "/buffer1.flzbuf", buff); } byte[] bt2 = File.ReadAllBytes(ppath + "/buffer1.flzbuf"); //decompress a byte buffer (we write the output buffer to a file for debug purposes.) if (fLZ.decompressBuffer(bt2, ref buff, true)) { lz4 = 1; File.WriteAllBytes(ppath + "/buffer1.tif", buff); } bt2 = null; bt = null; } }
//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); }
void DoTests() { //File tests //compress a file to brotli format. lz1 = brotli.compressFile(ppath + "/" + myFile, ppath + "/" + myFile + ".br", progress); //decompress the previously compressed archive lz2 = brotli.decompressFile(ppath + "/" + myFile + ".br", ppath + "/" + myFile + "Br.tif", progress2); //Buffer tests if (File.Exists(ppath + "/" + myFile)) { byte[] bt = File.ReadAllBytes(ppath + "/" + myFile); //compress a byte buffer (we write the output buffer to a file for debug purposes.) if (brotli.compressBuffer(bt, ref buff, progress3)) { lz3 = 1; File.WriteAllBytes(ppath + "/buffer1.brbuf", buff); } byte[] bt2 = File.ReadAllBytes(ppath + "/buffer1.brbuf"); //decompress a byte buffer (we write the output buffer to a file for debug purposes.) if (brotli.decompressBuffer(bt2, ref buff)) { lz4 = 1; File.WriteAllBytes(ppath + "/buffer1.tif", buff); } //FIXED BUFFER FUNCTION: int decompressedSize = brotli.decompressBuffer(bt2, fixedOutBuffer); if (decompressedSize > 0) { Debug.Log(" # Decompress Fixed size Buffer: " + decompressedSize); } //NEW BUFFER FUNCTION var newBuffer = brotli.decompressBuffer(bt2); if (newBuffer != null) { File.WriteAllBytes(ppath + "/buffer1NEW.tif", newBuffer); Debug.Log(" # new Buffer: " + newBuffer.Length); } bt2 = null; bt = null; newBuffer = null; } //make FileBuffer test on supported platfoms. #if (UNITY_IPHONE || UNITY_IOS || UNITY_STANDALONE_OSX || UNITY_ANDROID || UNITY_STANDALONE_LINUX || UNITY_EDITOR) && !UNITY_EDITOR_WIN //make a temp buffer to read a br file in. if (File.Exists(ppath + "/" + myFile + ".br")) { progress2[0] = 0; byte[] FileBuffer = File.ReadAllBytes(ppath + "/" + myFile + ".br"); fbuftest = brotli.decompressFile(ppath + "/" + myFile + ".br", ppath + "/" + myFile + "FB.tif", progress2, FileBuffer); } #endif }
public void Load() { if (File.Exists(Application.persistentDataPath + "/hsdata.tm")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/hsdata.tm", FileMode.Open); highScores = (Highscores)bf.Deserialize(file); file.Close(); } }
public void Unzip () { if( File.Exists( zipPath ) == false ){ Debug.LogError(zipPath + "is not found!"); System.Diagnostics.Process.Start(Path.GetDirectoryName(zipPath)); return; } /*ZipUtil.Unzip (zipPath, baseDirectryPath); System.Diagnostics.Process.Start(Path.GetDirectoryName(zipPath));*/ }
void DoTests() { //File tests //compress a file to flz with highest level of compression (2). lz1 = fLZ.compressFile(ppath + "/" + myFile, ppath + "/" + myFile + ".flz", 2, true, progress); //decompress the previously compressed archive lz2 = fLZ.decompressFile(ppath + "/" + myFile + ".flz", ppath + "/" + myFile + "B.tif", true, progress2); //Buffer tests if (File.Exists(ppath + "/" + myFile)) { byte[] bt = File.ReadAllBytes(ppath + "/" + myFile); //compress a byte buffer (we write the output buffer to a file for debug purposes.) if (fLZ.compressBuffer(bt, ref buff, 2, true)) { lz3 = 1; File.WriteAllBytes(ppath + "/buffer1.flzbuf", buff); } byte[] bt2 = File.ReadAllBytes(ppath + "/buffer1.flzbuf"); //decompress a byte buffer (we write the output buffer to a file for debug purposes.) if (fLZ.decompressBuffer(bt2, ref buff, true)) { lz4 = 1; File.WriteAllBytes(ppath + "/buffer1.tif", buff); } //FIXED BUFFER FUNCTION: int decommpressedSize = fLZ.decompressBufferFixed(bt2, ref fixedOutBuffer); if (decommpressedSize > 0) { Debug.Log(" # Decompress Fixed size Buffer: " + decommpressedSize); } bt2 = null; bt = null; } //make FileBuffer test on supported platfoms. #if (UNITY_IPHONE || UNITY_IOS || UNITY_STANDALONE_OSX || UNITY_ANDROID || UNITY_STANDALONE_LINUX || UNITY_EDITOR) && !UNITY_EDITOR_WIN //make a temp buffer to read an flz file in. if (File.Exists(ppath + "/" + myFile + ".flz")) { byte[] FileBuffer = File.ReadAllBytes(ppath + "/" + myFile + ".flz"); fbuftest = fLZ.decompressFile(null, ppath + "/" + myFile + ".flzFILE_BUFF.tif", true, progress2, FileBuffer); } #endif }
//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); } } } }
private void ChangeImage() { string imagePath = $"Assets/_Main/Editor/ScreenShots/{levelEditorSO.sceneFolderName[folderIndex]}/Level{folderIndex + 1}-{textFieldNumber}.png"; if (File.Exists(imagePath)) { imageOfLevel = new Texture2D(Screen.width - 25, 300); imageOfLevel.LoadImage(File.ReadAllBytes(imagePath)); imageExist = true; } else { imageExist = false; } }
void Start() { string filePath = Application.persistentDataPath + "/data"; if (File.Exists(filePath)) { string text = Encoding.ASCII.GetString(File.ReadAllBytes(filePath)); num = Int32.Parse(text); } num++; File.WriteAllBytes(filePath, Encoding.ASCII.GetBytes(num.ToString())); Text uiText = gameObject.GetComponent <Text>(); uiText.text = "You have launched this app " + num + " times."; }
public void Load() { string fileName = Application.persistentDataPath + "/hsdata.tm"; if (!File.Exists(fileName)) { return; } var bytes = File.ReadAllBytes(fileName); string result = System.Text.Encoding.UTF8.GetString(bytes); string[] tokens = result.Split(','); int[] scores = Array.ConvertAll <string, int>(tokens, int.Parse); highScores.highscore1 = scores[0]; highScores.highscore2 = scores[1]; highScores.highscore3 = scores[2]; }
// 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); }
void doFileBufferTest() { //For iOS, Android, MacOSX and Linux the plugins can handle a byte buffer as a file. (in this case the www.bytes) //This way you can extract the file or parts of it without writing it to disk. // // !!! Caution !!! Linux: While this works ok with unity 4.x.x, there is a bug introduced with unity5.x versions and might crash the app on // some Linux distributions. Use with caution! // #if (UNITY_IPHONE || UNITY_IOS || UNITY_STANDALONE_OSX || UNITY_ANDROID || UNITY_STANDALONE_LINUX || UNITY_EDITOR) && !UNITY_EDITOR_WIN if (File.Exists(ppath + "/" + myFile)) { byte[] www = File.ReadAllBytes(ppath + "/" + myFile); log = ""; lzres = lzma.doDecompress7zip(null, ppath + "/", true, true, null, www); log += lzres.ToString() + " | "; lzres = lzma.doDecompress7zip(null, ppath + "/", progress, false, true, null, www); log += lzres + " - prg: " + progress[0].ToString() + " | "; tsize = lzma.get7zInfo(null, null, www); log += "tsiz: " + tsize.ToString() + " #files: " + lzma.trueTotalFiles.ToString() + " | "; tsize = lzma.get7zSize(null, null, null, www); log += "tsiz: " + tsize.ToString() + " | "; var buffer = lzma.decode2Buffer(null, "2.txt", null, www); if (buffer != null) { log += "dec2buffer: ok" + "\n"; File.WriteAllBytes(ppath + "/2AAA_FILEBUFFER.txt", buffer); if (buffer.Length > 0) { Debug.Log("FileBuffer_Decode2Buffer: " + buffer.Length); } } } #endif }
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); }
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); }
IEnumerator buff2buffTest() { //Example on how to decompress an lzma compressed asset bundle from the streaming assets folder. //(editor, standalone example) for iOS, Android or WSA use an apropriate method to get the bytes buffer from the file. #if (UNITY_STANDALONE_LINUX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_WSA_10_0) && (!UNITY_IOS && !UNITY_ANDROID) || UNITY_EDITOR byte[] sa = File.ReadAllBytes(saPath + "/female_eyes.assetbundle"); if (lzma.decompressAssetBundle(sa, ref buff) == 0) { File.WriteAllBytes(ppath + "/female_eyes.assetbundle", buff); Debug.Log(" #-> AssetBundle Decompressed: ok"); } sa = null; #endif //BUFFER TO BUFFER lzma alone compression/decompression EXAMPLE // //An example on how to decompress an lzma alone file downloaded through www without storing it to disk //using just the www.bytes buffer. //Download a file. WWW w = new WWW("https://dl.dropboxusercontent.com/s/tzptxugk909pia1/google.jpg.lzma"); yield return(w); if (w.error == null) { //we decompress the lzma file in the buff buffer. if (lzma.decompressBuffer(w.bytes, ref buff) == 0) { pass1 = true; //we write it to disk just to check that the decompression was ok File.WriteAllBytes(ppath + "/google.jpg", buff); } else { Debug.Log("Error decompressing www.bytes to buffer"); pass1 = false; } } else { Debug.Log(w.error); } w.Dispose(); w = null; #if !(UNITY_WSA || UNITY_WSA_8_1 || UNITY_WP_8_1 || UNITY_WINRT_8_1) || UNITY_EDITOR //Example on how to compress a buffer. if (File.Exists(ppath + "/google.jpg")) { byte[] bt = File.ReadAllBytes(ppath + "/google.jpg"); //compress the data buffer into a compressed buffer if (lzma.compressBuffer(bt, ref buff)) { pass2 = true; //write it to disk just for checking purposes File.WriteAllBytes(ppath + "/google.jpg.lzma", buff); //print info Debug.Log("uncompressed size in lzma: " + BitConverter.ToUInt64(buff, 5)); Debug.Log("lzma size: " + buff.Length); } else { pass2 = false; Debug.Log("could not compress to buffer ..."); } //FIXED BUFFER FUNCTIONS: int compressedSize = lzma.compressBufferFixed(bt, ref fixedInBuffer); Debug.Log(" #-> Compress Fixed size Buffer: " + compressedSize); if (compressedSize > 0) { int decommpressedSize = lzma.decompressBufferFixed(fixedInBuffer, ref fixedOutBuffer); if (decommpressedSize > 0) { Debug.Log(" #-> Decompress Fixed size Buffer: " + decommpressedSize); } } bt = null; } #else yield return(false); #endif }
void Start() { #if (UNITY_WSA_8_1 || UNITY_WP_8_1 || UNITY_WINRT_8_1) && !UNITY_EDITOR ppath = UnityEngine.Windows.Directory.localFolder; #else ppath = Application.persistentDataPath; #endif // //we are setting the lzma.persitentDataPath so the get7zinfo, get7zSize, decode2Buffer functions can work on separate threads! //on WSA it must be 'Application.persistentDataPath' ! #if (UNITY_WSA_8_1 || UNITY_WP_8_1 || UNITY_WINRT_8_1) && !UNITY_EDITOR lzma.persitentDataPath = UnityEngine.Windows.Directory.localFolder; #else lzma.persitentDataPath = Application.persistentDataPath; #endif // #if UNITY_STANDALONE_OSX && !UNITY_EDITOR ppath = "."; #endif //Streaming Assets path on various platforms #if (!UNITY_IOS && !UNITY_ANDROID) || UNITY_EDITOR saPath = Application.dataPath + "/StreamingAssets"; #else #if UNITY_IOS saPath = Application.dataPath + "/Raw"; #endif #if UNITY_ANDROID saPath = "jar:file://" + Application.dataPath + "!/assets/"; #endif #endif // a reusable buffer to compress/decopmress data in/from buffers buff = new byte[0]; Debug.Log(ppath); Screen.sleepTimeout = SleepTimeout.NeverSleep; //download a 7z test file //StartCoroutine(Download7ZFile()); if (!File.Exists(ppath + "/" + myFile)) { StartCoroutine(Download7ZFile()); } else { downloadDone = true; } //download an lzma alone format file to test buffer 2 buffer encoding/decoding functions StartCoroutine(buff2buffTest()); #if UNITY_ANDROID && !UNITY_EDITOR getFromStreamingAssets("test2.7z", "t2.7z"); #endif }
public static bool Exists(string path) { return(File.Exists(path)); }
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("<", "<"); jsonData = jsonData.Replace(">", ">"); 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); } }
//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()); }