public static void Reload() { if (_asserBundleManifest == null) { AssetBundle manifestBundle = FileEncrypt.LoadFromFile(Application.streamingAssetsPath + "/" + SGK.PatchManager.GetPlatformName(), out manifestBundleFileStream); if (manifestBundle != null) { _asserBundleManifest = manifestBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); } } root = new AssetBundleInfo("", false); if (_asserBundleManifest == null) { return; } string[] bundles = _asserBundleManifest.GetAllAssetBundles(); for (int i = 0; i < bundles.Length; i++) { string[] keys = bundles[i].Split('/'); AssetBundleInfo parent = root; for (int j = 0; j < keys.Length; j++) { parent = parent.Add(keys[j], j == (keys.Length - 1)); } } }
public static void CopyAssetBundle(string dpath) { if (Directory.Exists(Application.streamingAssetsPath)) { Directory.Delete(Application.streamingAssetsPath, true); } Directory.CreateDirectory(Application.streamingAssetsPath); DirectoryInfo ndir = new DirectoryInfo(dpath); FileInfo[] files = ndir.GetFiles("*.*", SearchOption.AllDirectories); for (int i = 0; i < files.Length; ++i) { EditorUtility.DisplayProgressBar("copy assets", string.Format("正在拷贝资源 {0}/{1}", i, files.Length), (float)i / (float)files.Length); FileInfo f = files[i]; if (!f.Name.EndsWith(".manifest")) { string name = f.FullName.Replace("\\", "/"); name = name.Substring(name.IndexOf(dpath) + dpath.Length); string path = f.Directory.FullName.Replace("\\", "/"); path = path.Substring(path.IndexOf(dpath) + dpath.Length); if (!Directory.Exists(Application.streamingAssetsPath + path)) { Directory.CreateDirectory(Application.streamingAssetsPath + path); } FileEncrypt.Encrypt(f.FullName, Application.streamingAssetsPath + name); } } EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); }
public static LevelDataController Load(string path) { XmlSerializer serializer = new XmlSerializer(typeof(LevelDataController)); LevelDataController levels; if (!File.Exists(path)) { Stream reader; reader = new MemoryStream((Resources.Load("Puzzle_Initial", typeof(TextAsset)) as TextAsset).bytes); StreamReader textReader = new StreamReader(reader); levels = serializer.Deserialize(textReader) as LevelDataController; reader.Dispose(); } else { try { FileEncrypt.decrypt(path); } catch (Exception e) { } finally { FileStream stream = new FileStream(path, FileMode.Open); levels = serializer.Deserialize(stream) as LevelDataController; stream.Close(); } } return(levels); }
private void Encrypt_Click(object sender, RoutedEventArgs e) { string[] files = Directory.GetFiles(h.dir); foreach (string file in files) { if (Path.GetFileName(file) == "info.json") { continue; } if (Path.GetFileName(file) == "info.txt") { continue; } if (Path.GetExtension(file) == ".lock") { continue; } byte[] org = File.ReadAllBytes(file); byte[] enc = FileEncrypt.Default(org); File.Delete(file); File.WriteAllBytes(file + ".lock", enc); } h.files = h.files.Select(x => x + ".lock").ToArray(); h.encrypted = true; Process.Start(h.dir); }
public override void DownloadImage_Click(object sender, RoutedEventArgs e) { base.DownloadImage_Click(sender, e); string filename = CF.File.GetDownloadTitle(CF.File.SaftyFileName(h.name)); for (int i = 0; i < h.files.Length; i++) { Hitomi.HFile file = h.files[i]; WebClient wc = new WebClient(); wc.Headers.Add("referer", "https://hitomi.la/"); string folder = Global.config.download_folder.Get <string>(); if (!File.Exists($"{AppDomain.CurrentDomain.BaseDirectory}/{folder}/{filename}/{i}.jpg")) { bool fileen = Global.config.download_file_encrypt.Get <bool>(); h.FileInfo.encrypted = fileen; string path = $"{AppDomain.CurrentDomain.BaseDirectory}/{folder}/{filename}/{file.name}.{InternetP.GetDirFromHFileS(file)}.lock"; if (fileen) { FileEncrypt.DownloadAsync(wc, new Uri(file.url), path + ".lock"); } else { wc.DownloadFileAsync(new Uri(file.url), path); } } } }
public static string GetFullName(string name) { string ret = null; do { // 1. string path = Application.persistentDataPath + "/" + AssetVersion.Version + "/" + name; if (File.Exists(path)) { ret = path; break; } // 2. if (SGK.PatchManager.PatchFiles.ContainsKey(name)) { ret = Application.persistentDataPath + "/" + SGK.PatchManager.PatchFiles[name] + "/" + name; break; } // 3. if (FileEncrypt.BundleExistInPackage(name)) { ret = Application.streamingAssetsPath + "/" + name; break; } } while (false); return(ret); }
private void Encrypt_Click(object sender, RoutedEventArgs e) { foreach (string item in File2.GetDirectories(root: "", path, rootDir + Global.DownloadFolder)) { if (File.Exists($"{item}/info.json")) { JObject j = JObject.Parse(File.ReadAllText($"{item}/info.json")); j["encrypted"] = true; File.WriteAllText($"{item}/info.json", j.ToString()); } string[] files = Directory.GetFiles(item); foreach (string file in files) { if (Path.GetFileName(file) == "info.json") { continue; } if (Path.GetFileName(file) == "info.txt") { continue; } if (Path.GetExtension(file) == ".lock") { continue; } byte[] org = File.ReadAllBytes(file); byte[] enc = FileEncrypt.Default(org); File.Delete(file); File.WriteAllBytes(file + ".lock", enc); } } MessageBox.Show("전체 암호화 완료"); }
private void Hitomi_Download_Click(object sender, RoutedEventArgs e) { Task.Factory.StartNew(() => { string filename = File2.GetDownloadTitle(File2.SaftyFileName(h.name)); if (!Directory.Exists($"{AppDomain.CurrentDomain.BaseDirectory}/{Global.DownloadFolder}")) { Directory.CreateDirectory($"{AppDomain.CurrentDomain.BaseDirectory}/{Global.DownloadFolder}"); } Directory.CreateDirectory($"{AppDomain.CurrentDomain.BaseDirectory}/{Global.DownloadFolder}/{filename}"); h.dir = $"{AppDomain.CurrentDomain.BaseDirectory}/{Global.DownloadFolder}/{filename}"; h.Save($"{AppDomain.CurrentDomain.BaseDirectory}/{Global.DownloadFolder}/{filename}/info.json"); for (int i = 0; i < h.files.Length; i++) { string file = h.files[i]; WebClient wc = new WebClient(); wc.Headers.Add("referer", "https://hitomi.la/"); if (!File.Exists($"{AppDomain.CurrentDomain.BaseDirectory}/{Global.DownloadFolder}/{filename}/{i}.jpg")) { h.encrypted = Global.AutoFileEn; if (Global.AutoFileEn) { FileEncrypt.DownloadAsync(new Uri(file), $"{AppDomain.CurrentDomain.BaseDirectory}/{Global.DownloadFolder}/{filename}/{i}.jpg.lock"); } else { wc.DownloadFileAsync(new Uri(file), $"{AppDomain.CurrentDomain.BaseDirectory}/{Global.DownloadFolder}/{filename}/{i}.jpg"); } } } Process.Start($"{AppDomain.CurrentDomain.BaseDirectory}/{Global.DownloadFolder}/{filename}"); }); }
private void _file_encrypt() { if (_key_manager == null) { return; } try { if (_key_manager.IsDynamicEncryption) { FileEncrypt.EncryptFile(_local_path, _local_path + ".encrypted", _key_manager.RSAPublicKey, _local_data.SHA1, _file_encrypt_status_callback); } else if (_key_manager.IsStaticEncryption) { FileEncrypt.EncryptFile(_local_path, _local_path + ".encrypted", _key_manager.AESKey, _key_manager.AESIV, _local_data.SHA1, _file_encrypt_status_callback); } else { throw new Exception("密钥缺失"); } _local_path += ".encrypted"; if (!_remote_path.EndsWith(".bcsd")) { _remote_path += ".bcsd"; } } catch (Exception ex) { Tracer.GlobalTracer.TraceError(ex); } }
public bool MergePatch(string patch, PatchInfo info, ref Dictionary <string, string> localbundles) { int ret = -1; string bundleName = patch.Replace(".patch", ""); string fullpatch = Application.persistentDataPath + "/" + info.version + "/" + patch; string fullbundle = Application.persistentDataPath + "/" + info.version + "/" + bundleName; try { if (patch == bundleName) { ret = 0; } else { string old_file = ""; if (localbundles.ContainsKey(bundleName)) { old_file = GetBundlePathFromPackage(Application.persistentDataPath + "/" + localbundles[bundleName] + "/" + bundleName, fullbundle, false); } else { #if UNITY_ANDROID && !UNITY_EDITOR old_file = GetBundlePathFromPackage(bundleName, fullbundle, true); #else old_file = GetBundlePathFromPackage(Application.streamingAssetsPath + "/" + bundleName, fullbundle, false); #endif } if (!string.IsNullOrEmpty(old_file)) { ret = BSPatch.bspatch_merge(old_file, fullbundle, fullpatch); } } } catch (Exception ex) { Debug.LogError(ex); return(false); } if (ret == 0) { FileEncrypt.Encrypt(fullbundle, fullbundle); if (!localbundles.ContainsKey(bundleName)) { localbundles.Add(bundleName, info.version); } else { localbundles[bundleName] = info.version; } return(true); } return(false); }
public bool loadAssetBundle() { if (Asset == null) { Asset = FileEncrypt.LoadFromFile(FullName, out fileStream); mAssets = new Dictionary <string, Object>(); mAsyncs = new Dictionary <string, List <System.Action <Object> > >(); } return(Asset != null); }
public void Save(string path) { XmlSerializer serializer = new XmlSerializer(typeof(LevelDataController)); FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write); serializer.Serialize(stream, this); stream.Close(); FileEncrypt.encrypt(path); }
public string GetBundlePathFromPackage(string path, string npath, bool inPackage) { Stream r, w; byte[] bytes = new byte[1024 * 32]; if (inPackage) { if (zip_package == null) { #if UNITY_EDITOR zip_package = new ZipFile(Application.dataPath.Replace("Assets", "") + "build/fairy.apk"); #else zip_package = new ZipFile(Application.dataPath); #endif } var idx = zip_package.FindEntry("Assets/" + path, true); if (idx < 0) { return(null); } r = zip_package.GetInputStream(idx); } else { r = File.OpenRead(path); } w = File.Create(npath); while (true) { int count = r.Read(bytes, 0, bytes.Length); if (count > 0) { FileEncrypt.decode(bytes, (int)r.Position - count, count); w.Write(bytes, 0, count); } else { break; } } r.Flush(); w.Flush(); r.Close(); w.Close(); return(npath); }
//找到隐藏文件,改回后缀,解密,恢复为隐藏的已解密的txt文件/ public static FileStream DecryptionFile(string filePath, string encryptKey) { FileStream fs = null; string sourcefileName = filePath; if (!File.Exists(sourcefileName)) { return(fs); } string destfileName = System.IO.Path.ChangeExtension(sourcefileName, ".txt"); File.Move(sourcefileName, destfileName); File.SetAttributes(destfileName, FileAttributes.Normal); FileEncrypt.DecryptFile(destfileName, encryptKey, (int max, int value) => { }); fs = new FileStream(destfileName, FileMode.Open); fs = new FileStream(sourcefileName, FileMode.Open); return(fs); }
IEnumerator loadAssetBundleSync() { if (Asset == null) { var req = FileEncrypt.LoadFromFileAsync(FullName, out fileStream); if (req.assetBundle == null) { yield return(null); } Asset = req.assetBundle; if (Asset == null && fileStream != null) { fileStream.Dispose(); fileStream = null; } mAssets = new Dictionary <string, Object>(); mAsyncs = new Dictionary <string, List <System.Action <Object> > >(); } }
static void BuildData() { ResmapUtility.canAuto2Resmap = false; //不自动导入到resmap中 // 创建文件夹 Directory.CreateDirectory(ORIGINABPATH); DeleteFiles("data_"); //删除旧文件 // 重命名assetbundle FileInfo oldFile = new FileInfo(ORIGINABPATH + "/assetbundle"); if (oldFile.Exists) { oldFile.MoveTo(ORIGINABPATH + "/Tmp"); } ABNameUtility.ClearAllABNames(); EditorUtility.DisplayProgressBar("打包前准备", "正在生成resmap文件...", 0.1f); //重新生成Resmap文件 ResmapUtility.AddAllAsset(); EditorUtility.DisplayProgressBar("打包前准备", "正在处理Data文件...", 0.3f); ABNameUtility.SetDataABNames(); EditorUtility.DisplayProgressBar("打包", "正在打包Data文件...", 0.8f); FileEncrypt.Encrypt();//加密Txt AssetDatabase.Refresh(); BuildPipeline.BuildAssetBundles(ORIGINABPATH, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); AssetDatabase.Refresh(); ABNameUtility.ClearDataABNames(); EditorUtility.DisplayProgressBar("打包", "Data文件加密中...", 0.9f); EncryptAB("data_"); FileEncrypt.Decrypt();//还原Txt EditorUtility.ClearProgressBar(); // 删除新assetbundle UnityEditor.FileUtil.DeleteFileOrDirectory(ORIGINABPATH + "/assetbundle"); // 还原文件 if (oldFile.Exists) { oldFile.MoveTo(ORIGINABPATH + "/assetbundle"); } AssetDatabase.Refresh(); }
//将txt文件加密、改变后缀、隐藏文件及其父文件夹/ public static void EncryptionFile(string filePath, string mixedExtension, string encryptKey) { string sourcefileName = filePath; if (!File.Exists(sourcefileName)) { return; } FileEncrypt.EncryptFile(sourcefileName, encryptKey, (int max, int value) => { }); string destfileName = System.IO.Path.ChangeExtension(sourcefileName, mixedExtension); File.Move(sourcefileName, destfileName); File.SetAttributes(destfileName, FileAttributes.Hidden | FileAttributes.System); string folderPath = new FileInfo(sourcefileName).DirectoryName; File.SetAttributes(folderPath, FileAttributes.System); //设置添加系统文件夹/ File.SetAttributes(folderPath, FileAttributes.Hidden); //设置添加隐藏文件夹/ }
static void BuildAll() { ResmapUtility.canAuto2Resmap = false; //不自动导入到resmap中 // 创建文件夹 Directory.CreateDirectory(ORIGINABPATH); if (Directory.Exists(ABPATH)) { FileUtil.DeleteFileOrDirectory(ABPATH); } //记录所有的ab包,打包后,对无用的资源进行删除 EditorUtility.DisplayProgressBar("打包前准备", "收集已有AB资源...", 0.05f); Dictionary <string, ABInfo> _infoDic = new Dictionary <string, ABInfo>(); string[] files = Directory.GetFiles(ORIGINABPATH); for (int i = 0; i < files.Length; i++) { string path = files[i]; if (path.EndsWith(".meta") || path.EndsWith(".manifest")) { continue; } string fileName = Path.GetFileNameWithoutExtension(path); if (fileName.Equals("assetbundle")) { continue; } _infoDic.Add(fileName, new ABInfo() { abName = fileName, path = path }); } ABNameUtility.ClearAllABNames(); EditorUtility.DisplayProgressBar("打包前准备", "开始处理多语言资源...", 0.1f); MultiLngResDetach.StartDeal(); EditorUtility.DisplayProgressBar("打包前准备", "正在重新生成Resmap文件...", 0.2f); ResmapUtility.AddAllAsset(); EditorUtility.DisplayProgressBar("打包前准备", "Lua文件加密中...", 0.25f); LuaEncode.StartEncode(EditorUserBuildSettings.activeBuildTarget); EditorUtility.DisplayProgressBar("打包前准备", "配置文件加密中...", 0.3f); FileEncrypt.Encrypt(); AssetDatabase.Refresh(); EditorUtility.DisplayProgressBar("开始打包", "正在自动设置AB名...", 0.4f); ABNameUtility.SetAllABNames(); // 打包 EditorUtility.DisplayProgressBar("打包", "AB打包中...", 0.6f); AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(ORIGINABPATH, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); string[] bundles = manifest.GetAllAssetBundles(); for (int i = 0; i < bundles.Length; i++) { if (_infoDic.ContainsKey(bundles[i])) { _infoDic.Remove(bundles[i]); } } //删除老旧的ab包 foreach (KeyValuePair <string, ABInfo> pair in _infoDic) { ABInfo info = pair.Value; UnityEditor.FileUtil.DeleteFileOrDirectory(info.path); UnityEditor.FileUtil.DeleteFileOrDirectory(info.path + ".manifest"); } EditorUtility.DisplayProgressBar("收尾", "配置文件还原中...", 0.75f); FileEncrypt.Decrypt();//还原txt EditorUtility.DisplayProgressBar("收尾", "Lua文件还原中...", 0.8f); LuaEncode.EndEncode(); EditorUtility.DisplayProgressBar("收尾", "多语言资源还原中...", 0.85f); MultiLngResDetach.Revert(); EditorUtility.DisplayProgressBar("收尾", "清除AB名...", 0.9f); ABNameUtility.ClearAllABNames(); EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); ResmapUtility.canAutoToResmap = true; }
public void showResult() { audioCotroll.playInfoSound(); LevelDataController i = LevelDataController.Load(path); int k = 0; foreach (Level level in i.levels) { if (level.name.Equals("easy")) { easyTime = level.getTimeInArray(); easyScore = level.getScoreInArray(); easyDate = level.getDateInArray(); } if (level.name.Equals("normal")) { normalTime = level.getTimeInArray(); normalScore = level.getScoreInArray(); normalDate = level.getDateInArray(); } if (level.name.Equals("hard")) { hardTime = level.getTimeInArray(); hardScore = level.getScoreInArray(); hardDate = level.getDateInArray(); } Data [k].text = level.frequency.ToString(); k++; float time; int minutes; int seconds; if (level.frequency == 0) { Data [k].text = " - "; k++; time = 0f; Data [k].text = " - "; } else { Data [k].text = level.highestScore.ToString(); k++; time = level.shortestDuration; minutes = (int)time / 60; seconds = (int)time % 60; Data [k].text = string.Format("{0:00} : {1:00}", minutes, seconds); } k++; } pastResult.SetActive(true); if (File.Exists(path)) { FileEncrypt.encrypt(path); } }
private void _decrypt_file() { //未实例化密钥管理类 if (_key_manager == null) { return; } try { if (File.Exists(_output_path + ".decrypting")) { File.Delete(_output_path + ".decrypting"); //删除已有的冲突文件 } //重命名 if (_output_path.EndsWith(".bcsd")) { //xxxxx.bcsd -> xxxxx.decrypting _output_path = _output_path.Substring(0, _output_path.Length - 5); File.Move(_output_path + ".bcsd", _output_path + ".decrypting"); } else { File.Move(_output_path, _output_path + ".decrypting"); //xxxxx.xx -> xxxxx.xx.decrypting } var fs = new FileStream(_output_path + ".decrypting", FileMode.Open, FileAccess.Read, FileShare.None); var identifier = fs.ReadByte(); //读取文件首字节判断加密类型 fs.Close(); if (identifier == FileEncrypt.FLG_DYNAMIC_KEY && _key_manager.HasRsaKey) { try { //解密文件并删除加密文件 FileEncrypt.DecryptFile(_output_path + ".decrypting", _output_path, _key_manager.RSAPrivateKey); File.Delete(_output_path + ".decrypting"); } catch { //出错后取消解密,将文件重新命名 File.Move(_output_path + ".decrypting", _output_path); } } else if (identifier == FileEncrypt.FLG_STATIC_KEY && _key_manager.HasAesKey) { try { FileEncrypt.DecryptFile(_output_path + ".decrypting", _output_path, _key_manager.AESKey, _key_manager.AESIV); File.Delete(_output_path + ".decrypting"); } catch { File.Move(_output_path + ".decrypting", _output_path); } } else { //加密类型不匹配,重新命名 File.Move(_output_path + ".decrypting", _output_path); } } catch (Exception ex) { Tracer.GlobalTracer.TraceError(ex); } }
private async void DownloadImage_Click(object sender, RoutedEventArgs e) { bool hiyobi = ftype == Hitomi.Type.Hiyobi; if (ftype == Hitomi.Type.Folder) { bool result = await new InternetP(index: int.Parse(h.id)).isHiyobi(); hiyobi = result; } Hitomi h2 = null; if (hiyobi) { h2 = await new HiyobiLoader(text: h.id).Parser(); } if (!hiyobi) { h2 = await new InternetP(index: int.Parse(h.id)).HitomiData2(); } if (h2 == null) { return; } string folder = h.type == Hitomi.Type.Folder ? h.dir : Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Global.DownloadFolder, File2.GetDownloadTitle(File2.SaftyFileName(h2.name))); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } h = h2; File.WriteAllText(Path.Combine(folder, "info.json"), JObject.FromObject(h2).ToString()); foreach (string file in Directory.GetFiles(folder)) { if (file.EndsWith(".lock") || file.EndsWith(".jpg")) { File.Delete(file); } } for (int i = 0; i < h2.files.Length; i++) { string file = h2.files[i]; WebClient wc = new WebClient(); if (!hiyobi) { wc.Headers.Add("referer", "https://hitomi.la/"); } h.encrypted = Global.AutoFileEn; if (Global.AutoFileEn) { FileEncrypt.DownloadAsync(new Uri(file), $"{folder}/{i}.jpg.lock"); } else { wc.DownloadFileAsync(new Uri(file), $"{folder}/{i}.jpg"); } if (i == 0) { wc.DownloadFileCompleted += ImageDownloadCompleted; } } Process.Start(folder); }
private void btnEncrypt_Click(object sender, EventArgs e) { #region 验证 if (txtPwd.Text == "") { MessageBox.Show("密码不能为空", "提示"); return; } if (txtPwdCfm.Text == "") { MessageBox.Show("xwuser密码不能为空", "提示"); return; } #endregion if (openFileDialog1.ShowDialog() == DialogResult.OK) { Thread thread = new Thread(new ParameterizedThreadStart(delegate(object obj) { try { InvokeDelegate invokeDelegate = delegate() { pbFile.Value = 0; lblProgressFile.Text = "0%"; pbDir.Visible = false; lblProgressDir.Visible = false; pbFile.Visible = false; lblProgressFile.Visible = false; lblShowPath.Text = "加密文件:" + openFileDialog1.FileName; lblShowPath.Visible = true; DisableBtns(); }; InvokeUtil.Invoke(this, invokeDelegate); DateTime t1 = DateTime.Now; FileEncrypt.EncryptFile(openFileDialog1.FileName, txtPwd.Text, RefreshFileProgress); DateTime t2 = DateTime.Now; string t = t2.Subtract(t1).TotalSeconds.ToString("0.00"); if (MessageBox.Show("加密成功,耗时" + t + "秒", "提示") == DialogResult.OK) { invokeDelegate = delegate() { EnableBtns(); }; InvokeUtil.Invoke(this, invokeDelegate); } } catch (Exception ex) { if (MessageBox.Show("加密失败:" + ex.Message, "提示") == DialogResult.OK) { InvokeDelegate invokeDelegate = delegate() { EnableBtns(); }; InvokeUtil.Invoke(this, invokeDelegate); } } })); thread.Start(); } }