Пример #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 Source GetSource(string pkg, string file)
        {
            bool   finded = false;
            Source s      = default;

            foreach (var item in Packages)
            {
                if (item.Name == pkg)
                {
                    finded = true;
                    foreach (var itemm in item.Sources)
                    {
                        if (itemm.Name == file)
                        {
                            s = itemm;
                        }
                    }
                }
            }
            if (!finded)
            {
                LogFramework.WriteNewLog($"Unknown {pkg} in package list.", CClass, this, null, LogEnums.ResultCode.ErrorMethod);
                return(null);
            }
            return(s);
        }
Пример #3
0
 private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
 {
     LogFramework.WriteNewLog($"Critical error: {((Exception)(e.ExceptionObject)).Message}", CClass, Instance, null, LogEnums.ResultCode.Error, ConsoleColor.Green, (Exception)e.ExceptionObject);
     //CommandActions.Mes($"{((Exception)(e.ExceptionObject)).Message}", ConsoleColor.Red);
     UnException?.Invoke(e);
     LogFramework.SaveLogs();
 }
Пример #4
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);
        }
Пример #5
0
 private static void CurrentDomain_ProcessExit(object sender, EventArgs e)
 {
     MeasureSpeed = Stopwatch.StartNew();
     Exit?.Invoke(e);
     StoppedTimeMs = MeasureSpeed.Elapsed.TotalMilliseconds;
     MeasureSpeed.Stop();
     LogFramework.WriteNewLog($"Good bye! (ended for {StoppedTimeMs} ms.)", CClass, Instance, null, LogEnums.ResultCode.OKMethod);
     LogFramework.SaveLogs();
 }
Пример #6
0
        public AppStabilizer()
        {
            CClass.CheckCreateAdd(this, nameof(AppStabilizer));
            LogFramework.WriteNewLog($"Welcome!", CClass, this, null, LogEnums.ResultCode.StartingMethod);
            MeasureSpeed = Stopwatch.StartNew();
            AppDomain.CurrentDomain.ProcessExit        += ProcessExit;
            AppDomain.CurrentDomain.UnhandledException += UnhandledException;
            Start?.Invoke(new EventArgs());

            StartedTimeMs = MeasureSpeed.Elapsed.TotalMilliseconds;
            MeasureSpeed.Stop();
            LogFramework.WriteNewLog($"Started for {StartedTimeMs} ms.", CClass, this, null, LogEnums.ResultCode.OKMethod);
        }
Пример #7
0
        public void AddToPkg(string pkg, Source s)
        {
            bool finded = false;

            foreach (var item in Packages)
            {
                if (item.Name == pkg)
                {
                    finded = true;
                    item.Sources.Add(s);
                    LogFramework.WriteNewLog($"{s.Name} added to {item.Name} in package list.", CClass, this, null, LogEnums.ResultCode.OKMethod);
                }
            }
            if (!finded)
            {
                LogFramework.WriteNewLog($"Unknown {pkg} in package list.", CClass, this, null, LogEnums.ResultCode.ErrorMethod);
            }
        }
Пример #8
0
        public static Source Pack(string filepath)
        {
            byte[] data = default;
            string name = "";
            int    size = 0;
            string type = "";

            try
            {
                using (var item = File.OpenRead(filepath))
                {
                    data = new byte[item.Length];
                    item.Read(data, 0, (int)item.Length);
                    var path     = item.Name.Split('\\');
                    var n        = path[path.Length - 1];
                    var fullname = n.Split('.').ToList();
                    type = fullname[fullname.Count - 1];
                    fullname.RemoveAt(fullname.Count - 1);
                    var newname = "";
                    for (var i = 0; i != fullname.Count; i++)
                    {
                        if (i != fullname.Count - 1)
                        {
                            newname += $"{fullname[i]}.";
                        }
                        else
                        {
                            newname += $"{fullname[i]}";
                        }
                    }
                    name = newname;
                    size = (int)item.Length;
                }
            }
            catch (Exception ex)
            {
                LogFramework.WriteNewLog($"Failed pack file.", PackageManager.CClass, PackageManager.Instance, null, LogEnums.ResultCode.ErrorMethod, ConsoleColor.Red, ex);
                return(null);
            }
            var s = new Source(name, type, size, data);

            LogFramework.WriteNewLog($"{name}.{type} is packed.", PackageManager.CClass, PackageManager.Instance, null, LogEnums.ResultCode.OKMethod);
            return(s);
        }
Пример #9
0
        public ProtectedPackage GetPkg(string pkg)
        {
            bool             finded = false;
            ProtectedPackage pp     = default;

            foreach (var item in Packages)
            {
                if (item.Name == pkg)
                {
                    finded = true;
                    pp     = item;
                }
            }
            if (!finded)
            {
                LogFramework.WriteNewLog($"Unknown {pkg} in package list.", CClass, this, null, LogEnums.ResultCode.ErrorMethod);
                return(null);
            }
            return(pp);
        }
Пример #10
0
        public void Unpack(string folderpath)
        {
            var name = $"{Name}.{Type}";
            var data = Data;

            try
            {
                if (!Directory.Exists(folderpath))
                {
                    Directory.CreateDirectory(folderpath);
                }
                using (var item = File.OpenWrite($"{folderpath}\\{name}"))
                {
                    item.Write(data, 0, data.Length);
                }
                LogFramework.WriteNewLog($"{name} is unpacked.", PackageManager.CClass, PackageManager.Instance, null, LogEnums.ResultCode.OKMethod);
            }
            catch (Exception ex)
            {
                LogFramework.WriteNewLog($"Failed unpack file.", PackageManager.CClass, PackageManager.Instance, null, LogEnums.ResultCode.ErrorMethod, ConsoleColor.Red, ex);
            }
        }
Пример #11
0
 public void AddPkg(ProtectedPackage pp)
 {
     Packages.Add(pp);
     LogFramework.WriteNewLog($"{pp.Name} loaded to package list.", CClass, this, null, LogEnums.ResultCode.OKMethod);
 }
Пример #12
0
 /// <summary>
 /// Invokes custom log.
 /// </summary>
 public virtual void InvokeLog(string text, LogEnums.ResultCode resultCode, ConsoleDebug.ActionResult action = null, ConsoleColor cColor = ConsoleColor.Green, Exception ex = null)
 {
     LogFramework.WriteNewLog(text, CClass, this, action, resultCode, cColor, ex);
 }
Пример #13
0
        /// <summary>
        /// Load library lists.
        /// </summary>
        public DResult LoadAllLibraries(params CParameter[] paramms)
        {
            LogFramework.WriteNewLog($"Starting manager dynamic & static libraries", CClass, this, LoadAllLibraries, LogEnums.ResultCode.StartingMethod);
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            var mes = $"Manager dynamic & static libraries enabled";

            return(DResult.C(CDebugResult.Working, mes, LoadAllLibraries, CClass, this));

            /*
             * LogFramework.WriteNewLog($"Loading dynamic libraries", LogEnums.Tools.ResourceManager, new Action(LoadAllLibraries), LogEnums.ResultCode.StartingMethod, null);
             * try
             * {
             *  foreach (DynamicLibrary item in DynamicLibraries)
             *  {
             *      LogFramework.WriteNewLog($"Loading {item.Name} v{item.Ver}", LogEnums.Tools.ResourceManager, new Action(LoadAllLibraries), LogEnums.ResultCode.StartingInMethod, null);
             *      try
             *      {
             *          if (!item.Load())
             *              LogFramework.WriteNewLog($"Failed Load {item.Name} v{item.Ver}", LogEnums.Tools.ResourceManager, new Action(LoadAllLibraries), LogEnums.ResultCode.ErrorInMethod, null);
             *      }
             *      catch (Exception e)
             *      {
             *          LogFramework.WriteNewLog($"Failed Load {item.Name} v{item.Ver}", LogEnums.Tools.ResourceManager, new Action(LoadAllLibraries), LogEnums.ResultCode.ErrorInMethod, e);
             *      }
             *      finally
             *      {
             *          LogFramework.WriteNewLog($"Loaded {item.Name} v{item.Ver}", LogEnums.Tools.ResourceManager, new Action(LoadAllLibraries), LogEnums.ResultCode.OKInMethod, null);
             *      }
             *  }
             * }
             * catch (Exception e)
             * {
             *  LogFramework.WriteNewLog($"Failed load dynamic libraries", LogEnums.Tools.ResourceManager, new Action(LoadAllLibraries), LogEnums.ResultCode.ErrorMethod, null);
             * }
             * finally
             * {
             *  LogFramework.WriteNewLog($"Dynamic libraries loaded", LogEnums.Tools.ResourceManager, new Action(LoadAllLibraries), LogEnums.ResultCode.OKMethod, null);
             * }
             *
             * LogFramework.WriteNewLog($"Loading static libraries", LogEnums.Tools.ResourceManager, new Action(LoadAllLibraries), LogEnums.ResultCode.StartingMethod, null);
             * try
             * {
             *  foreach (var item in DynamicLibraries)
             *  {
             *      LogFramework.WriteNewLog($"Loading {item.Name} v{item.Ver}", LogEnums.Tools.ResourceManager, new Action(LoadAllLibraries), LogEnums.ResultCode.StartingInMethod, null);
             *      try
             *      {
             *          AppDomain.CurrentDomain.Load(item.Raw);
             *      }
             *      catch (Exception e)
             *      {
             *          LogFramework.WriteNewLog($"Failed Load {item.Name} v{item.Ver}", LogEnums.Tools.ResourceManager, new Action(LoadAllLibraries), LogEnums.ResultCode.ErrorInMethod, e);
             *      }
             *      finally
             *      {
             *          LogFramework.WriteNewLog($"Loaded {item.Name} v{item.Ver}", LogEnums.Tools.ResourceManager, new Action(LoadAllLibraries), LogEnums.ResultCode.OKInMethod, null);
             *      }
             *  }
             * }
             * catch (Exception e)
             * {
             *  LogFramework.WriteNewLog($"Failed load static libraries", LogEnums.Tools.ResourceManager, new Action(LoadAllLibraries), LogEnums.ResultCode.ErrorMethod, null);
             * }
             * finally
             * {
             *  LogFramework.WriteNewLog($"Static libraries loaded", LogEnums.Tools.ResourceManager, new Action(LoadAllLibraries), LogEnums.ResultCode.OKMethod, null);
             * }
             */
        }
Пример #14
0
        Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            try
            {
                string assembly = args.Name.Split(',')[0];

                LogFramework.WriteNewLog($"Trying load {assembly}", CClass, this, LoadAllLibraries, LogEnums.ResultCode.StartingInMethod);

                if (CheckAssembly(assembly, out var assembl))
                {
                    LogFramework.WriteNewLog($"Loaded {assembly}", CClass, this, LoadAllLibraries, LogEnums.ResultCode.OKInMethod);
                    return(Assembly.Load(assembl));
                }
                else if (assembly.EndsWith(".resources"))
                {
                    LogFramework.WriteNewLog($"Failed load : unknown type of {assembly}", CClass, this, LoadAllLibraries, LogEnums.ResultCode.WarnInMethod);
                    return(null);
                }

                else
                {
                    var excp = new Exception($"Сборка: \"{assembly}\" не может быть загружена.");
                    LogFramework.WriteNewLog($"Failed load {assembly}", CClass, this, LoadAllLibraries, LogEnums.ResultCode.ErrorInMethod, ConsoleColor.Red, excp);
                    throw excp;
                }


                /*
                 * switch (assembly)
                 * {
                 *  case "OpenTK":
                 *      {
                 *          //MessageBox.Show("OpenTK loaded");
                 *          App.LibraryManager.SetResolvedLibrary($"{assembly}.dll");
                 *          App.LibraryManager.SetLoadedLibrary($"{assembly}.dll");
                 *          return Assembly.Load(App.LibraryManager.GetLibrary($"{assembly}.dll").Raw);
                 *      }
                 *  case "OpenTK.GLControl":
                 *      {
                 *          //MessageBox.Show("OpenTK.GLControl loaded");
                 *          App.LibraryManager.SetResolvedLibrary($"{assembly}.dll");
                 *          App.LibraryManager.SetLoadedLibrary($"{assembly}.dll");
                 *          return Assembly.Load(App.LibraryManager.GetLibrary($"{assembly}.dll").Raw);
                 *      }
                 *  case "System.Windows.Controls.DataVisualization.Toolkit":
                 *      {
                 *          //MessageBox.Show("System.Windows.Controls.DataVisualization.Toolkit loaded");
                 *          App.LibraryManager.SetResolvedLibrary($"{assembly}.dll");
                 *          App.LibraryManager.SetLoadedLibrary($"{assembly}.dll");
                 *          return Assembly.Load(App.LibraryManager.GetLibrary($"{assembly}.dll").Raw);
                 *      }
                 *
                 *
                 *  default:
                 *
                 * }
                 */
            }
            catch (Exception ex)
            {
                LogFramework.WriteNewLog($"Failed load lib", CClass, this, LoadAllLibraries, LogEnums.ResultCode.ErrorInMethod, ConsoleColor.Red, ex);
                return(null);
            }
        }