Esempio n. 1
0
        public static void flushOldCachedFilesAsync(UpdateWindow.iUpgradeableCollection upgradeData)
        {
            if (MainForm.Instance.Settings.AlwaysBackUpFiles)
            {
                return;
            }

            string updateCache = MainForm.Instance.Settings.MeGUIUpdateCache;

            if (String.IsNullOrEmpty(updateCache) || !Directory.Exists(updateCache))
            {
                return;
            }

            List <string> urls = new List <string>();

            foreach (UpdateWindow.iUpgradeable u in upgradeData)
            {
                if (!String.IsNullOrEmpty(u.AvailableVersion.Url))
                {
                    urls.Add(u.AvailableVersion.Url.ToLowerInvariant());
                }
                if (!urls.Contains(u.CurrentVersion.Url) && !String.IsNullOrEmpty(u.CurrentVersion.Url))
                {
                    urls.Add(u.CurrentVersion.Url.ToLowerInvariant());
                }
            }

            DirectoryInfo fi = new DirectoryInfo(updateCache);

            FileInfo[] files = fi.GetFiles("*.zip");
            foreach (FileInfo f in files)
            {
                if (urls.IndexOf(f.Name.ToLowerInvariant()) >= 0)
                {
                    continue;
                }

                if (DateTime.Now - f.LastWriteTime > new TimeSpan(REMOVE_PACKAGE_AFTER_DAYS, 0, 0, 0, 0))
                {
                    f.Delete();
                    MainForm.Instance.UpdateHandler.AddTextToLog("Deleted cached file " + f.Name, ImageType.Information, false);
                }
            }
            files = fi.GetFiles("*.7z");
            foreach (FileInfo f in files)
            {
                if (urls.IndexOf(f.Name.ToLowerInvariant()) >= 0)
                {
                    continue;
                }

                if (DateTime.Now - f.LastWriteTime > new TimeSpan(REMOVE_PACKAGE_AFTER_DAYS, 0, 0, 0, 0))
                {
                    f.Delete();
                    MainForm.Instance.UpdateHandler.AddTextToLog("Deleted cached file " + f.Name, ImageType.Information, false);
                }
            }
        }
Esempio n. 2
0
        public static void RemoveOldFiles()
        {
            UpdateWindow.iUpgradeableCollection upgradeData = MainForm.Instance.UpdateHandler.UpdateData;

            try
            {
                string updateCache = MainForm.Instance.Settings.MeGUIUpdateCache;
                if (String.IsNullOrEmpty(updateCache) || !Directory.Exists(updateCache))
                {
                    return;
                }

                List <string> urls = new List <string>();
                foreach (UpdateWindow.iUpgradeable u in upgradeData)
                {
                    if (!String.IsNullOrEmpty(u.AvailableVersion.Url))
                    {
                        urls.Add(u.AvailableVersion.Url.ToLowerInvariant());
                    }
                    if (!urls.Contains(u.CurrentVersion.Url) && !String.IsNullOrEmpty(u.CurrentVersion.Url))
                    {
                        urls.Add(u.CurrentVersion.Url.ToLowerInvariant());
                    }
                }

                DirectoryInfo fi    = new DirectoryInfo(updateCache);
                FileInfo[]    files = fi.GetFiles("*.zip");
                foreach (FileInfo f in files)
                {
                    if (urls.IndexOf(f.Name.ToLowerInvariant()) >= 0)
                    {
                        continue;
                    }

                    if (f.Name.StartsWith("_obsolete_"))
                    {
                        continue;
                    }

                    f.LastWriteTimeUtc = DateTime.UtcNow;
                    File.Delete(Path.Combine(updateCache, "_obsolete_" + f.Name));
                    f.MoveTo(Path.Combine(updateCache, "_obsolete_" + f.Name));
                    MainForm.Instance.UpdateHandler.AddTextToLog("Marked file as obsolete: " + f.Name.Substring(10), ImageType.Information, false);
                }

                files = fi.GetFiles("*.7z");
                foreach (FileInfo f in files)
                {
                    if (urls.IndexOf(f.Name.ToLowerInvariant()) >= 0)
                    {
                        continue;
                    }

                    if (f.Name.StartsWith("_obsolete_"))
                    {
                        continue;
                    }

                    f.LastWriteTimeUtc = DateTime.UtcNow;
                    File.Delete(Path.Combine(updateCache, "_obsolete_" + f.Name));
                    f.MoveTo(Path.Combine(updateCache, "_obsolete_" + f.Name));
                    MainForm.Instance.UpdateHandler.AddTextToLog("Marked file as obsolete: " + f.Name.Substring(10), ImageType.Information, false);
                }

                if (!MainForm.Instance.Settings.AlwaysBackUpFiles)
                {
                    files = fi.GetFiles("_obsolete_*.*");
                    foreach (FileInfo f in files)
                    {
                        if (urls.IndexOf(f.Name.ToLowerInvariant()) >= 0)
                        {
                            continue;
                        }

                        // delete file if it is obsolete for more than 90 days
                        if (DateTime.Now - f.LastWriteTime > new TimeSpan(90, 0, 0, 0, 0))
                        {
                            f.Delete();
                            MainForm.Instance.UpdateHandler.AddTextToLog("Deleted obsolete file: " + f.Name.Substring(10), ImageType.Information, false);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MainForm.Instance.UpdateHandler.AddTextToLog("Old package data could not be cleaned: " + ex.Message, ImageType.Error, false);
            }

            if (MainForm.Instance.Settings.AlwaysBackUpFiles)
            {
                return;
            }

            try
            {
                string strMeGUILogPath = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + @"\logs";
                if (String.IsNullOrEmpty(strMeGUILogPath) || !Directory.Exists(strMeGUILogPath))
                {
                    return;
                }

                DirectoryInfo fi    = new DirectoryInfo(strMeGUILogPath);
                FileInfo[]    files = fi.GetFiles("*.log");
                foreach (FileInfo f in files)
                {
                    // delete file if it is obsolete for more than 90 days
                    if (DateTime.Now - f.LastWriteTime > new TimeSpan(90, 0, 0, 0, 0))
                    {
                        f.Delete();
                        MainForm.Instance.UpdateHandler.AddTextToLog("Deleted obsolete file: " + f.Name.Substring(10), ImageType.Information, false);
                    }
                }
            }
            catch (Exception ex)
            {
                MainForm.Instance.UpdateHandler.AddTextToLog("Old log data could not be cleaned: " + ex.Message, ImageType.Error, false);
            }
        }