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; } }
public void Load(PersistableObject obj) { byte[] data = File.ReadAllBytes(_savePath); var reader = new BinaryReader(new MemoryStream(data)); obj.Load(new GameDataReader(reader, -reader.ReadInt32())); }
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; } }
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 InstallLevels() { loading.SetActive (true); LevelsInstalling = true; yield return new WaitForSeconds (0.0f); //call the download coroutine to download a test file DirectoryInfo directoryInfo = new DirectoryInfo (Application.persistentDataPath); print ("Streaming Assets Path: " + Application.persistentDataPath); FileInfo[] allFiles = directoryInfo.GetFiles ("*.demoidlevel"); foreach (FileInfo file in allFiles) { var fileBuffer = File.ReadAllBytes (Application.persistentDataPath + "/" + file.Name); plog ("Validate: " + lzip.validateFile (null, fileBuffer).ToString ()); //decompress the downloaded file zres = lzip.decompress_File (null, ppath + "/", progress, fileBuffer, progress2); plog ("decompress: " + zres.ToString ()); yield return new WaitForSecondsRealtime (1.0f); if (Application.platform == RuntimePlatform.Android) { System.IO.File.Delete(Application.persistentDataPath + "/" + file.Name); } if (Application.platform == RuntimePlatform.IPhonePlayer) { System.IO.File.Delete("/private" + Application.persistentDataPath+"/"+file.Name); //File.Delete ("/private"+file.ToString()); } } Rcanvas.SetActive (true); loading.SetActive (false); AlreadyInstalled = true; LevelsInstalling = false; }
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 }
void DoDecompression_FileBuffer(string file, string folder) { Debug.Log("DoDecompression_FileBuffer: " + folder + ": file: " + file); var fileBuffer = File.ReadAllBytes(file); zres = lzip.decompress_File(null, folder, progress, fileBuffer, progress2); plog("DoDecompression_FileBuffer decompress: " + zres.ToString()); }
public static string Read(string path) { string result = ""; #if UNITY_WINRT && !UNITY_EDITOR byte[] bytes = File.ReadAllBytes(path); result = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length); #else result = File.ReadAllText(path); #endif return(result); }
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 }
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."; }
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; } }
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]; }
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 }
//these functions demonstrate how to extract data from a zip file in a byte buffer. // void DoDecompression_FileBuffer() { #if (UNITY_IPHONE || UNITY_IOS || UNITY_STANDALONE_OSX || UNITY_ANDROID || UNITY_STANDALONE_LINUX || UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_WSA) //we read a downloaded zip from the Persistent data path. It could be also a file in a www.bytes buffer. var fileBuffer = File.ReadAllBytes(ppath + "/testZip.zip"); plog("Validate: " + lzip.validateFile(null, fileBuffer).ToString()); //decompress the downloaded file zres = lzip.decompress_File(null, ppath + "/", progress, fileBuffer, progress2); plog("decompress: " + zres.ToString()); plog("true total files: " + lzip.getTotalFiles(null, fileBuffer)); plog("total entries: " + lzip.getTotalEntries(null, fileBuffer)); //entry exists bool eres = lzip.entryExists(null, "dir1/dir2/test2.bmp", fileBuffer); plog("entry exists: " + eres.ToString()); //extract an entry zres = lzip.extract_entry(null, "dir1/dir2/test2.bmp", ppath + "/test22B.bmp", fileBuffer, progress2); plog("extract entry: " + zres.ToString()); plog(""); //get the uncompressed size of a specific file in the zip archive plog("get entry size: " + lzip.getEntrySize(null, "dir1/dir2/test2.bmp", fileBuffer).ToString()); plog(""); //extract a file in a zip archive to a byte buffer (referenced buffer method) plog("entry2Buffer1: " + lzip.entry2Buffer(null, "dir1/dir2/test2.bmp", ref reusableBuffer2, fileBuffer).ToString()); // File.WriteAllBytes(ppath + "/out.bmp", reusableBuffer2); //extract a file in a zip archive to a byte buffer (new buffer method) var newBuffer = lzip.entry2Buffer(null, "dir1/dir2/test2.bmp", fileBuffer); 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", reusableBuffer2); plog(""); //get file info of the zip file (names, uncompressed and compressed sizes) plog("total bytes: " + lzip.getFileInfo(null, null, fileBuffer).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(""); #endif }
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 }