예제 #1
0
 public static void Export(ProtectedPackage pkg, string folderpath)
 {
     try
     {
         if (!Directory.Exists(folderpath))
         {
             Directory.CreateDirectory(folderpath);
         }
         var path = $@"{folderpath}\{pkg.Name}.{FileType}";
         using (var item = File.OpenWrite(path))
         {
             var         data = pkg.ObjectToByteArray();
             CacheMemory cm   = new CacheMemory(data, "test");
             cm.Encrypt();
             cm.Compress();
             data = cm.ToByteArray();
             item.Write(data, 0, data.Length);
         }
     }
     catch (Exception ex)
     {
         LogFramework.WriteNewLog("Failed import package.", PackageManager.CClass, PackageManager.Instance, null, LogEnums.ResultCode.ErrorMethod, ConsoleColor.Red, ex);
         return;
     }
     LogFramework.WriteNewLog("Package exported.", PackageManager.CClass, PackageManager.Instance, null, LogEnums.ResultCode.OKMethod);
 }
예제 #2
0
        public static ProtectedPackage Import(string pkgpath)
        {
            ProtectedPackage pp = default;

            try
            {
                byte[] data;
                using (var item = File.OpenRead($"{pkgpath}"))
                {
                    data = new byte[item.Length];
                    item.Read(data, 0, (int)item.Length);

                    var cm = new CacheMemory(data, "test");
                    cm.Decompress();
                    cm.Decrypt();

                    cm.Read(data, 0, (int)cm.Length);
                    data = cm.ToByteArray();
                }
                pp = data.ByteArrayToObject <ProtectedPackage>();
            }
            catch (Exception ex)
            {
                LogFramework.WriteNewLog("Failed import package.", PackageManager.CClass, PackageManager.Instance, null, LogEnums.ResultCode.ErrorMethod, ConsoleColor.Red, ex);
            }
            LogFramework.WriteNewLog("Package imported.", PackageManager.CClass, PackageManager.Instance, null, LogEnums.ResultCode.OKMethod);
            return(pp);
        }