Ejemplo n.º 1
0
        /// <summary>
        /// Check for update
        /// </summary>
        public static void AutoUpdate()
        {
            // Issue #520: intercept any possible exception and fail quietly
            try
            {
                Directory.CreateDirectory(GlobalSetting.ConfigDir(Dir.Temporary));

                string updateXML = GlobalSetting.ConfigDir(Dir.Temporary, "update.xml");
                Update up        = new Update(new Uri("https://imageglass.org/checkforupdate"), updateXML);

                if (File.Exists(updateXML))
                {
                    File.Delete(updateXML);
                }

                if (!up.IsError &&
                    up.CheckForUpdate(GlobalSetting.StartUpDir("ImageGlass.exe")) &&
                    up.Info.VersionType.ToLower() == "stable")
                {
                    frmCheckForUpdate f = new frmCheckForUpdate();
                    f.ShowDialog();
                }
            }
            catch (Exception e)
            {
            }

            Application.Exit();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Load theme list
        /// </summary>
        private void LoadThemeList()
        {
            //add default theme
            var defaultTheme = new Theme(GlobalSetting.StartUpDir(@"DefaultTheme\config.xml"));

            _themeList.Add(defaultTheme);
            cmbTheme.Items.Clear();
            cmbTheme.Items.Add(defaultTheme.Name);
            cmbTheme.SelectedIndex = 0;


            string themeFolder = GlobalSetting.ConfigDir(Dir.Themes);

            //get the current theme
            var currentTheme = GlobalSetting.GetConfig("Theme", "default");


            if (Directory.Exists(themeFolder))
            {
                foreach (string d in Directory.GetDirectories(themeFolder))
                {
                    string configFile = Path.Combine(d, "config.xml");

                    if (File.Exists(configFile))
                    {
                        Theme th = new Theme(d);

                        //invalid theme
                        if (!th.IsThemeValid)
                        {
                            continue;
                        }

                        _themeList.Add(th);
                        cmbTheme.Items.Add(th.Name);

                        if (currentTheme.ToLower().CompareTo(th.ThemeFolderName.ToLower()) == 0)
                        {
                            cmbTheme.SelectedIndex = cmbTheme.Items.Count - 1;
                        }
                    }
                }
            }
            else
            {
                Directory.CreateDirectory(themeFolder);
            }
        }
Ejemplo n.º 3
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            Directory.CreateDirectory(GlobalSetting.ConfigDir(Dir.Temporary));

            picStatus.Image = igcmd.Properties.Resources.loading;
            Thread t = new Thread(new ThreadStart(CheckForUpdate))
            {
                Priority     = ThreadPriority.BelowNormal,
                IsBackground = true
            };

            t.Start();

            FileVersionInfo fv = FileVersionInfo.GetVersionInfo(GlobalSetting.StartUpDir("ImageGlass.exe"));

            txtUpdates.Text = $"Current version: {fv.FileVersion}\r\n------------------------------\r\n\r\n";

            //CheckForUpdate();
        }
Ejemplo n.º 4
0
        static void Main(string[] argv)
        {
            // Check if the start up directory writable
            GlobalSetting.IsStartUpDirWritable = GlobalSetting.CheckStartUpDirWritable();


            // Set up Startup Profile to improve launch performance
            // https://blogs.msdn.microsoft.com/dotnet/2012/10/18/an-easy-solution-for-improving-app-launch-performance/
            ProfileOptimization.SetProfileRoot(GlobalSetting.ConfigDir());
            ProfileOptimization.StartProfile("igstartup.profile");

            // Issue #360: IG periodically searching for dismounted device
            SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS);

            // Windows Vista or later
            if (Environment.OSVersion.Version.Major >= 6)
            {
                SetProcessDPIAware();
            }

            Guid guid = new Guid(appGuid);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            // Save App version
            GlobalSetting.SetConfig("AppVersion", Application.ProductVersion.ToString());


            #region Check First-launch Configs
            var firstLaunchVersion = 0;

            int.TryParse(GlobalSetting.GetConfig("FirstLaunchVersion", "0"), out firstLaunchVersion);

            if (firstLaunchVersion < GlobalSetting.FIRST_LAUNCH_VERSION)
            {
                Process p = new Process();
                p.StartInfo.FileName  = GlobalSetting.StartUpDir("igcmd.exe");
                p.StartInfo.Arguments = "firstlaunch";

                try
                {
                    p.Start();
                }
                catch { }

                Application.Exit();
                return;
            }
            #endregion


            #region Auto update
            string lastUpdateConfig = GlobalSetting.GetConfig("AutoUpdate", "7/26/1991 12:13:08 AM");

            if (lastUpdateConfig != "0")
            {
                DateTime lastUpdate = DateTime.Now;

                if (DateTime.TryParseExact(lastUpdateConfig, "M/d/yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out lastUpdate))
                {
                    //Check for update every 3 days
                    if (DateTime.Now.Subtract(lastUpdate).TotalDays > 3)
                    {
                        RunCheckForUpdate();
                    }
                }
                else
                {
                    RunCheckForUpdate();
                }
            }


            void RunCheckForUpdate()
            {
                Process p = new Process();

                p.StartInfo.FileName  = GlobalSetting.StartUpDir("igcmd.exe");
                p.StartInfo.Arguments = "igautoupdate";
                p.Start();

                //save last update
                GlobalSetting.SetConfig("AutoUpdate", DateTime.Now.ToString("M/d/yyyy HH:mm:ss"));
            }

            #endregion


            #region Multi instances
            //get current config
            GlobalSetting.IsAllowMultiInstances = bool.Parse(GlobalSetting.GetConfig("IsAllowMultiInstances", "true"));

            //check if allows multi instances
            if (GlobalSetting.IsAllowMultiInstances)
            {
                Application.Run(formMain = new frmMain());
            }
            else
            {
                //single instance is required
                using (SingleInstance singleInstance = new SingleInstance(guid))
                {
                    if (singleInstance.IsFirstInstance)
                    {
                        singleInstance.ArgumentsReceived += SingleInstance_ArgumentsReceived;
                        singleInstance.ListenForArgumentsFromSuccessiveInstances();

                        Application.Run(formMain = new frmMain());
                    }
                    else
                    {
                        singleInstance.PassArgumentsToFirstInstance(Environment.GetCommandLineArgs());
                    }
                }
            } //end check multi instances
            #endregion
        }