예제 #1
0
        public static void Cleanup()
        {
            ScriptCache?.WaitClose();
            Logger?.Dispose();
            FileTypeDetector?.Dispose();
            NativeGlobalCleanup();

            FileHelper.CleanBaseTempDir();
        }
예제 #2
0
        /// <summary>
        /// Launch after Application.Current is loaded
        /// </summary>
        public static void Init()
        {
            string baseDir = Environment.CurrentDirectory;

            for (int i = 0; i < Args.Length; i++)
            {
                if (Args[i].Equals("/basedir", StringComparison.OrdinalIgnoreCase))
                {
                    if (i + 1 < Args.Length)
                    {
                        baseDir = Path.GetFullPath(Args[i + 1]);
                        if (!Directory.Exists(baseDir))
                        {
                            MessageBox.Show($"Directory [{baseDir}] does not exist", "Invalid BaseDir", MessageBoxButton.OK, MessageBoxImage.Error);
                            Environment.Exit(1); // Force Shutdown
                        }
                        Environment.CurrentDirectory = baseDir;
                    }
                    else
                    {
                        // ReSharper disable once LocalizableElement
                        Console.WriteLine("\'/basedir\' must be used with path\r\n");
                    }
                }
                else if (Args[i].Equals("/?", StringComparison.OrdinalIgnoreCase) ||
                         Args[i].Equals("/help", StringComparison.OrdinalIgnoreCase) ||
                         Args[i].Equals("/h", StringComparison.OrdinalIgnoreCase))
                {
                    // ReSharper disable once LocalizableElement
                    Console.WriteLine("Sorry, help message not implemented\r\n");
                }
            }
            BaseDir = baseDir;

            // Database directory
            string dbDir = Path.Combine(BaseDir, "Database");

            if (!Directory.Exists(dbDir))
            {
                Directory.CreateDirectory(dbDir);
            }

            // Log Database
            string logDbFile = Path.Combine(dbDir, "PEBakeryLog.db");

            try
            {
                Logger = new Logger(logDbFile);
                Logger.SystemWrite(new LogInfo(LogState.Info, "PEBakery launched"));
            }
            catch (SQLiteException e)
            { // Update failure
                string msg = $"SQLite Error : {e.Message}\r\n\r\nLog database is corrupted.\r\nPlease delete PEBakeryLog.db and restart.";
                MessageBox.Show(msg, "SQLite Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                if (Application.Current != null)
                {
                    Application.Current.Shutdown(1);
                }
                else
                {
                    Environment.Exit(1);
                }
            }

            // Init ProjectCollection
            Projects = new ProjectCollection(BaseDir);

            // Setting File
            string settingFile = Path.Combine(BaseDir, "PEBakery.ini");

            Setting = new Setting(settingFile);
            Setting.ApplySetting();

            // Custom Title
            if (Setting.Interface.UseCustomTitle)
            {
                MainViewModel.TitleBar = Setting.Interface.CustomTitle;
            }

            // Load script cache
            if (Setting.Script.EnableCache)
            {
                string cacheDbFile = Path.Combine(dbDir, "PEBakeryCache.db");
                try
                {
                    ScriptCache = new ScriptCache(cacheDbFile);
                    Logger.SystemWrite(new LogInfo(LogState.Info, $"ScriptCache enabled, {ScriptCache.Table<CacheModel.ScriptCache>().Count()} cached scripts found"));
                }
                catch (SQLiteException e)
                { // Load failure
                    string msg = $"SQLite Error : {e.Message}\r\n\r\nCache database is corrupted.\r\nPlease delete PEBakeryCache.db and restart.";
                    MessageBox.Show(msg, "SQLite Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                    if (Application.Current != null)
                    {
                        Application.Current.Shutdown(1);
                    }
                    else
                    {
                        Environment.Exit(1);
                    }
                }
            }
            else
            {
                Logger.SystemWrite(new LogInfo(LogState.Info, "ScriptCache disabled"));
            }
        }
예제 #3
0
파일: Project.cs 프로젝트: mirsys/pebakery
 /// <summary>
 /// Load scripts of the project.
 /// .link files additionally requires another stage of loading later.
 /// </summary>
 /// <param name="spis">ScriptParseInfo of .script files and .link files.</param>
 /// <param name="scriptCache">ScriptCache instance. Set to null if cache is disabled.</param>
 /// <param name="progress">Delegate for reporting progress</param>
 /// <returns></returns>
 internal List <LogInfo> Load(ScriptCache scriptCache, IList <ScriptParseInfo> spis, IProgress <(LoadReport Type, string Path)> progress)
예제 #4
0
 public ProjectCollection(string baseDir, ScriptCache scriptCache)
 {
     this.baseDir     = baseDir;
     this.projectRoot = Path.Combine(baseDir, "Projects");
     this.scriptCache = scriptCache;
 }
예제 #5
0
파일: Global.cs 프로젝트: pebakery/pebakery
        /// <summary>
        /// Launch after Application.Current is loaded
        /// </summary>
        public static void Init()
        {
            // Set fallback BaseDir
            string baseDir = BaseDir = Environment.CurrentDirectory;

            // Setup unhandled exception handler (requires BaseDir to be set)
            AppDomain.CurrentDomain.UnhandledException += AppDomain_UnhandledException;

            // Run ArgumentParser
            ArgumentParser  argParser = new ArgumentParser();
            PEBakeryOptions opts      = argParser.Parse(Args);

            if (opts == null)        // Arguments parse fail
            {
                Environment.Exit(1); // Force Shutdown
            }
            // Setup BaseDir
            if (opts.BaseDir != null)
            {
                baseDir = Path.GetFullPath(opts.BaseDir);
                if (Directory.Exists(baseDir) == false)
                {
                    MessageBox.Show($"Directory [{baseDir}] does not exist.\r\nRun [PEBkaery --help] for commnad line help message.", "PEBakery CommandLine Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Environment.Exit(1); // Force Shutdown
                }
                Environment.CurrentDirectory = BaseDir = baseDir;
            }

            // Database directory
            string dbDir = Path.Combine(BaseDir, "Database");

            if (!Directory.Exists(dbDir))
            {
                Directory.CreateDirectory(dbDir);
            }

            // Log Database
            string logDbFile = Path.Combine(dbDir, "PEBakeryLog.db");

            try
            {
                Logger = new Logger(logDbFile);
                Logger.SystemWrite(new LogInfo(LogState.Info, "PEBakery launched"));
            }
            catch (SQLiteException)
            { // Update failure -> retry with clearing existing log db
                File.Delete(logDbFile);
                try
                {
                    Logger = new Logger(logDbFile);
                    Logger.SystemWrite(new LogInfo(LogState.Info, "PEBakery launched, log cleared due to an error"));
                }
                catch (SQLiteException e)
                { // Unable to continue -> raise an error message
                    string msg = $"SQLite Error : {e.Message}\r\n\r\nThe Log database is corrupted and was not able to be repaired.\r\nPlease delete {dbDir}\\PEBakeryLog.db and restart.";
                    MessageBox.Show(msg, "SQLite Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                    if (Application.Current != null)
                    {
                        Application.Current.Shutdown(1);
                    }
                    else
                    {
                        Environment.Exit(1);
                    }
                }
            }

            // Init ProjectCollection
            Projects = new ProjectCollection(BaseDir);

            // Setting File
            string settingFile = Path.Combine(BaseDir, "PEBakery.ini");

            Setting = new Setting(settingFile);
            Setting.ApplySetting();

            // Custom Title
            if (Setting.Interface.UseCustomTitle)
            {
                MainViewModel.TitleBar = Setting.Interface.CustomTitle;
            }

            // Init script cache DB, regardless of Setting.Script.EnableCache
            string cacheDbFile = Path.Combine(dbDir, "PEBakeryCache.db");

            try
            {
                ScriptCache = new ScriptCache(cacheDbFile);
                int cachedScriptCount = ScriptCache.Table <CacheModel.ScriptCache>().Count();

                if (Setting.Script.EnableCache)
                {
                    Logger.SystemWrite(new LogInfo(LogState.Info, $"ScriptCache enabled, {cachedScriptCount} cached scripts found"));
                }
                else
                {
                    Logger.SystemWrite(new LogInfo(LogState.Info, "ScriptCache disabled"));
                }
            }
            catch (SQLiteException)
            { // Load failure -> Fallback, delete and remake database
                File.Delete(cacheDbFile);
                try
                {
                    ScriptCache = new ScriptCache(cacheDbFile);
                    Logger.SystemWrite(new LogInfo(LogState.Info, $"ScriptCache enabled, cache cleared due to an error"));
                }
                catch (SQLiteException e)
                { // Unable to continue -> raise an error message
                    string msg = $"SQLite Error : {e.Message}\r\n\r\nThe Cache database is corrupted and was not able to be repaired.\r\nPlease delete {dbDir}\\PEBakeryCache.db and restart.";
                    MessageBox.Show(msg, "SQLite Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                    if (Application.Current != null)
                    {
                        Application.Current.Shutdown(1);
                    }
                    else
                    {
                        Environment.Exit(1);
                    }
                }
            }
        }