/// <summary>Deletes a modfile and binary from the cache.</summary> public static bool DeleteModfileAndBinaryZip(int modId, int modfileId) { bool isSuccessful = IOUtilities.DeleteFile(CacheClient.GenerateModfileFilePath(modId, modfileId)); isSuccessful = (IOUtilities.DeleteFile(CacheClient.GenerateModBinaryZipFilePath(modId, modfileId)) && isSuccessful); return(isSuccessful); }
/// <summary>Deletes a modfile and binary from the cache.</summary> public static bool DeleteModfileAndBinaryZip(int modId, int modfileId) { string modfilePath = CacheClient.GenerateModfileFilePath(modId, modfileId); string zipPath = CacheClient.GenerateModBinaryZipFilePath(modId, modfileId); bool success = true; if (!LocalDataStorage.DeleteFile(modfilePath)) { success = false; } if (!LocalDataStorage.DeleteFile(zipPath)) { success = false; } return(success); }
public static ModBinaryRequest GetActiveModBinary(ModProfile profile) { string zipFilePath = CacheClient.GenerateModBinaryZipFilePath(profile.id, profile.activeBuild.id); ModBinaryRequest request; if (File.Exists(zipFilePath)) { request = new ModBinaryRequest(); request.isDone = true; request.binaryFilePath = zipFilePath; } else { request = DownloadClient.DownloadModBinary(profile.id, profile.activeBuild.id, CacheClient.GenerateModBinaryZipFilePath(profile.id, profile.activeBuild.id)); request.succeeded += (r) => CacheClient.SaveModfile(r.modfile); } return(request); }
public static void UnzipModBinaryToLocation(ModfileStub modfile, string unzipLocation) { string zipFilePath = CacheClient.GenerateModBinaryZipFilePath(modfile.modId, modfile.id); if (File.Exists(zipFilePath)) { try { Directory.CreateDirectory(unzipLocation); using (var zip = Ionic.Zip.ZipFile.Read(zipFilePath)) { zip.ExtractAll(unzipLocation); } } catch (Exception e) { Debug.LogError("[mod.io] Unable to extract binary to given location." + "\nLocation: " + unzipLocation + "\n\n" + Utility.GenerateExceptionDebugString(e)); } } }
public static void DeleteModfileAndBinaryZip(int modId, int modfileId) { CacheClient.DeleteFile(CacheClient.GenerateModfileFilePath(modId, modfileId)); CacheClient.DeleteFile(CacheClient.GenerateModBinaryZipFilePath(modId, modfileId)); }
public static void GetDownloadedBinaryStatus(ModfileStub modfile, Action <ModBinaryStatus> callback) { string binaryFilePath = CacheClient.GenerateModBinaryZipFilePath(modfile.modId, modfile.id); ModBinaryStatus status; if (File.Exists(binaryFilePath)) { try { if ((new FileInfo(binaryFilePath)).Length != modfile.fileSize) { status = ModBinaryStatus.Error_FileSizeMismatch; } else { using (var md5 = System.Security.Cryptography.MD5.Create()) { using (var stream = System.IO.File.OpenRead(binaryFilePath)) { var hash = md5.ComputeHash(stream); string hashString = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); bool isValidHash = (hashString == modfile.fileHash.md5); Debug.Log("Hash Validation = [" + isValidHash + "]" + "\nExpected Hash: " + modfile.fileHash.md5 + "\nDownload Hash: " + hashString); if (isValidHash) { status = ModBinaryStatus.CompleteAndVerified; } else { status = ModBinaryStatus.Error_HashCheckFailed; } } } } } #pragma warning disable 0168 catch (Exception e) { status = ModBinaryStatus.Error_UnableToReadFile; } #pragma warning restore 0168 } else if (File.Exists(binaryFilePath + ".download")) { status = ModBinaryStatus.PartiallyDownloaded; } else { status = ModBinaryStatus.Missing; } if (callback != null) { callback(status); } }