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; }
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; }
//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); }
// 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 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; }
// 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 ()); } } } } } }
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; } }
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; }
/// <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 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 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)); }
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; }
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; } }
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; }
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 Save() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/hsdata.tm"); bf.Serialize(file, highScores); file.Close(); }
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 void ExportToFile() { var path = Path.Combine(Application.dataPath, $"{Guid.NewGuid().ToString()}"); var levelString = new TokenizedLevelMap(_builder.Build()).ToString(); File.WriteAllBytes(path, Encoding.UTF8.GetBytes(levelString)); Debug.Log($"Wrote Level to {path}"); }
public static void Write(string path, string contents) { #if UNITY_WINRT && !UNITY_EDITOR byte[] bytes = System.Text.Encoding.UTF8.GetBytes(contents); File.WriteAllBytes(path, bytes); #else File.WriteAllText(path, contents); #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));*/ }
public void Save() { string[] scores = new string[3]; scores[0] = highScores.highscore1.ToString(); scores[1] = highScores.highscore2.ToString(); scores[2] = highScores.highscore3.ToString(); string scoresAsString = string.Join(",", scores); var bytes = System.Text.Encoding.UTF8.GetBytes(scoresAsString); File.WriteAllBytes(Application.persistentDataPath + "/hsdata.tm", bytes); }
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 }
//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); }