private static void Proc_DataReceived(object sender, DataReceivedEventArgs e)
 {
     if (e.Data != null)
     {
         EasyLogger.Info(e.Data);
     }
 }
 public static void DeleteSetFiles()
 {
     // Delete Files
     foreach (string file in Default.FilesToDelete)
     {
         bool deleted = false;
         if (File.Exists(file))
         {
             try
             {
                 File.Delete(file);
                 deleted = true;
             }
             catch (Exception ex)
             {
                 deleted = false;
                 EasyLogger.Error(file + " : " + ex);
                 continue;
             }
             if (deleted)
             {
                 EasyLogger.Info("Deleting file: " + file);
             }
         }
     }
 }
        private void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
        {
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                if (CheckForInternet.Connected())
                {
                    NoInternetWarning.Source = null;

                    ConnectedToInternet = true;

                    if (((MainWindow)Application.Current.MainWindow).AlertTextBody.Text == "You may not be connected to the internet...")
                    {
                        ParseWeatherXML.NWSAlertsInfo();
                    }
                }
                else
                {
                    ConnectedToInternet = false;

                    Thread thread = new Thread(EarlyNetCheck)
                    {
                        IsBackground = true
                    };
                    thread.Start();

                    NoInternetWarning.Source = new BitmapImage(new Uri(@"pack://application:,,,/NWS Alerts;component/Resources/NoInternetWarning.png", UriKind.Absolute));

                    EasyLogger.Info("It appears that you do not have an internet connection. We will retry later.");
                }
            }));
        }
Beispiel #4
0
        private static void Proc_DataReceived(object sender, DataReceivedEventArgs e)
        {
            if (e.Data != null)
            {
                if (e.Data.StartsWith("Program:"))
                {
                    string file = e.Data.Replace("Program:", "").TrimStart();

                    if (Path.IsPathRooted(file) && !Path.GetDirectoryName(file).StartsWith(Environment.GetFolderPath(Environment.SpecialFolder.Windows)))
                    {
                        if (!FileExistance.FileExists(file))
                        {
                            try
                            {
                                if (!BackedUp)
                                {
                                    string datetime = DateTime.Now.ToString("Mdhms");

                                    RunCommand("netsh", "advfirewall export " + "\"" + AppDomain.CurrentDomain.BaseDirectory + "\\Backup\\" + datetime + "_FirwallPolicy.wfw" + "\"");

                                    BackedUp = true;
                                }

                                EasyLogger.Info("Removing (inbound/outbound) " + file + " from Windows Firewall...");
                                RunCommand("netsh", "advfirewall firewall delete rule name=all program= " + "\"" + file + "\"");
                            }
                            catch (Exception ex)
                            {
                                EasyLogger.Error(ex.Message);
                            }
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public static void DeleteSetPaths()
        {
            // Delete Files
            foreach (string dir in Default.DirectoriesToDelete)
            {
                bool deleted = false;
                if (Directory.Exists(dir))
                {
                    try
                    {
                        Directory.Delete(dir, true);
                        deleted = true;
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            using (Process proc = new Process())
                            {
                                proc.StartInfo.WindowStyle     = ProcessWindowStyle.Hidden;
                                proc.StartInfo.CreateNoWindow  = true;
                                proc.StartInfo.UseShellExecute = false;
                                proc.StartInfo.FileName        = "cmd.exe";
                                proc.StartInfo.Arguments       = "/C takeown /a /r /d Y /f" + dir;
                                proc.Start();
                                proc.WaitForExit();
                            }
                            var file = new FileInfo(dir.ToString())
                            {
                                Attributes = FileAttributes.Normal
                            };

                            foreach (var subDirectoryPath in Directory.GetDirectories(dir))
                            {
                                var directoryInfo = new DirectoryInfo(subDirectoryPath);
                                foreach (var filePath in directoryInfo.GetFiles())
                                {
                                    file = new FileInfo(filePath.ToString())
                                    {
                                        Attributes = FileAttributes.Normal
                                    };
                                }
                            }

                            Directory.Delete(dir, true);
                        }
                        catch (Exception)
                        {
                            deleted = false;
                            EasyLogger.Error(dir + " : " + ex);
                            continue;
                        }
                    }
                    if (deleted)
                    {
                        EasyLogger.Info("Deleting directory: " + dir);
                    }
                }
            }
        }
        private void CloseSettings_Click(object sender, RoutedEventArgs e)
        {
            bool UpdateWeather = false;

            if (LatTextBox.Text != Default.LatValue)
            {
                UpdateWeather = true;
            }

            if (LongTextBox.Text != Default.LongValue)
            {
                UpdateWeather = true;
            }

            SaveSettings();

            if (UpdateWeather)
            {
                EasyLogger.Info("Current location has changed... ");

                Updating = true;

                Thread thread = new Thread(() => DesktopWeatherXML(PreWeatherString + Default.LatValue + "," + Default.LongValue, NWSAlertsDirectory + "\\WeatherInfo.xml"))
                {
                    IsBackground = true
                };
                thread.Start();
            }

            Grid1.Children.Remove(SettingsPanel);
        }
Beispiel #7
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            // Final log entry
            EasyLogger.Info("Closing down...");

            // Dispose EasyLogger
            EasyLogger.RemoveListener();
        }
Beispiel #8
0
        public static void SetAsHidden()
        {
            // Hide Files
            foreach (var hideFile in Default.FilesToHide)
            {
                try
                {
                    var filePath = Environment.ExpandEnvironmentVariables(hideFile);
                    if (File.Exists(filePath))
                    {
                        if ((File.GetAttributes(filePath) & FileAttributes.Hidden) != FileAttributes.Hidden)
                        {
                            FileAttributes attributes = File.GetAttributes(filePath);
                            if (attributes != FileAttributes.Hidden || attributes != FileAttributes.System)
                            {
                                EasyLogger.Info("Hiding file: " + filePath);

                                File.SetAttributes(filePath, File.GetAttributes(filePath) | FileAttributes.Hidden);
                                File.SetAttributes(filePath, File.GetAttributes(filePath) | FileAttributes.System);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    EasyLogger.Error(hideFile + " : " + ex);
                    continue;
                }
            }

            // Hide Directories
            foreach (var hideFile in Default.DirectoriesToHide)
            {
                try
                {
                    var filePath = Environment.ExpandEnvironmentVariables(hideFile);
                    if (Directory.Exists(filePath))
                    {
                        if ((File.GetAttributes(filePath) & FileAttributes.Hidden) != FileAttributes.Hidden)
                        {
                            EasyLogger.Info("Hiding directory: " + filePath);

                            FileAttributes attributes = File.GetAttributes(filePath);
                            if (attributes != FileAttributes.Hidden || attributes != FileAttributes.System)
                            {
                                File.SetAttributes(filePath, File.GetAttributes(filePath) | FileAttributes.Hidden);
                                File.SetAttributes(filePath, File.GetAttributes(filePath) | FileAttributes.System);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    EasyLogger.Error(hideFile + " : " + ex);
                    continue;
                }
            }
        }
Beispiel #9
0
        public static void SetService(string serviceName, string status)
        {
            using (var mo = new ManagementObject(string.Format("Win32_Service.Name=\"{0}\"", serviceName)))
            {
                EasyLogger.Info("Setting service: " + serviceName + " to: " + status);

                mo.InvokeMethod("ChangeStartMode", new object[] { status });
            }
        }
        public static void ShowDateCheckBox_Checked(object sender, RoutedEventArgs e)
        {
            EasyLogger.Info("Setting date to show");

            Default.ShowDate = true;

            if (Default.ShowTime)
            {
                timer.Start();
            }
        }
        private static void DeleteEmptySubdirectories(string parentDirectory)
        {
            foreach (string directory in Directory.GetDirectories(parentDirectory))
            {
                if (directory != Environment.GetFolderPath(Environment.SpecialFolder.Startup) && directory != Environment.GetFolderPath(Environment.SpecialFolder.CommonStartup) && directory != programs + "\\Administrative Tools" && directory != commonPrograms + "\\Administrative Tools" && directory != programs + "\\Windows Administrative Tools" && directory != commonPrograms + "\\Windows Administrative Tools" && directory != programs + "\\Windows System" && directory != commonPrograms + "\\Windows System" && directory != programs + "\\Windows Accessories" && directory != commonPrograms + "\\Windows Accessories" && directory != programs + "\\Windows Ease of Access" && directory != commonPrograms + "\\Windows Ease of Access" && directory != programs + "\\Games" && directory != commonPrograms + "\\Games")
                {
                    try
                    {
                        DeleteEmptySubdirectories(directory);
                    }
                    catch { continue; }

                    try
                    {
                        int totalDirectories = 0;
                        foreach (string dir in Directory.GetDirectories(directory))
                        {
                            totalDirectories++;
                        }
                        if (totalDirectories == 0)
                        {
                            int totalFiles = 0;
                            foreach (string file in Directory.GetFiles(directory))
                            {
                                if (Path.GetFileName(file.ToLower()) != "desktop.ini" && Path.GetFileName(file.ToLower()) != "thumbs.db")
                                {
                                    totalFiles++;
                                }
                            }
                            if (totalFiles == 0)
                            {
                                foreach (string file in Directory.GetFiles(directory))
                                {
                                    if (Path.GetFileName(file.ToLower()) == "desktop.ini" || Path.GetFileName(file.ToLower()) == "thumbs.db")
                                    {
                                        File.Delete(file);
                                    }
                                }
                                EasyLogger.Info("Removing empty directory: " + directory);
                                try
                                {
                                    Directory.Delete(directory);
                                }
                                catch (Exception ex)
                                {
                                    EasyLogger.Error(ex);
                                }
                            }
                        }
                    }
                    catch { continue; }
                }
            }
        }
Beispiel #12
0
        private void Log_Click(object sender, EventArgs e)
        {
            // Used to isolate errors
            EasyLogger.Error("The log file path is: " + EasyLogger.LogFile);

            // Used to isolate warnings
            EasyLogger.Warning("The log file path is: " + EasyLogger.LogFile);

            // Used to isolate information
            EasyLogger.Info("The log file path is: " + EasyLogger.LogFile);
        }
        private void ShowDateCheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            EasyLogger.Info("Setting date not to show");

            CurrentDate.Content = "";

            Default.ShowDate = false;

            if (!Default.ShowTime)
            {
                timer.Stop();
            }
        }
Beispiel #14
0
        internal static void ExecuteBackup()
        {
            try
            {
                Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "BACKUPS");
                EasyLogger.Info("Creating a new backup of the database...");

                ProcessStartInfo startInfo = new ProcessStartInfo()
                {
                    FileName       = "sqllocaldb",
                    Arguments      = "stop MSSQLLocalDB",
                    CreateNoWindow = true,
                    WindowStyle    = ProcessWindowStyle.Hidden
                };
                Process process = new Process
                {
                    StartInfo = startInfo
                };
                process.Start();
                process.WaitForExit();
            }
            catch (Exception ex)
            {
                ErrorsHaveOccurred = true;
                EasyLogger.Error("BackupDatabase - @ExecuteBackup(1): " + ex);
                MessageBox.Show(ex.Message, "Followers", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            try
            {
                if (File.Exists(databaseBackup))
                {
                    File.Copy(databaseBackup, databaseOLDBackup, true);
                }
                if (File.Exists(sourceBackup))
                {
                    File.Copy(sourceBackup, databaseBackup, true);
                }
                if (File.Exists(databaseBackup))
                {
                    File.SetLastWriteTime(databaseBackup, DateTime.Now);
                }
            }
            catch (Exception ex)
            {
                ErrorsHaveOccurred = true;
                EasyLogger.Error("BackupDatabase - @ExecuteBackup(2): " + ex);
                MessageBox.Show(ex.Message, "Followers", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #15
0
        private void Custom_Click(object sender, EventArgs e)
        {
            // Backup the log files in this location
            EasyLogger.BackupLogs(EasyLogger.LogDirectory + "TEST_CUSTOM.log");

            // Need to dispose so that we can set our new log location
            EasyLogger.RemoveListener();

            // Need to add a listener again
            EasyLogger.AddListener(EasyLogger.LogFile);

            // Log something
            EasyLogger.Info("TEST: The log file path is: " + EasyLogger.LogFile);
        }
Beispiel #16
0
        public static void SettingsMenuItem_Click(object sender, EventArgs e)
        {
            SettingsWindow settings = new SettingsWindow();

            settings.ShowDialog();

            if (SettingsChanged)
            {
                Default.Reload();
                EasyLogger.Info("Settings have changed; Reparsing Weather...");

                ParseWeatherXML.LastUpdate = DateTimeOffset.Now.AddMonths(-1);
                ParseWeatherXML.NWSAlertsInfo();
            }
        }
Beispiel #17
0
        public static void LocationWindowMenuItem_Click(object sender, EventArgs e)
        {
            LocationBox locationBox = new LocationBox();

            locationBox.ShowDialog();

            if (SettingsChanged)
            {
                Default.Reload();
                EasyLogger.Info("Location settings have changed; Reparsing Weather...");

                ParseWeatherXML.LastUpdate = DateTimeOffset.Now.AddMonths(-1);
                ParseWeatherXML.NWSAlertsInfo();
            }
        }
Beispiel #18
0
        public TEST()
        {
            // Backup the log files in this location after 30 days (Put here any location else EasyLogger.LogFile is default)
            EasyLogger.BackupLogs(EasyLogger.LogFile, 30);

            // Backup the log files in this location (Put here any location else EasyLogger.LogFile is default)
            //EasyLogger.BackupLogs(EasyLogger.LogFile);

            // Add listener so we can start logging
            EasyLogger.AddListener(EasyLogger.LogFile);

            // Log something
            EasyLogger.Info("TEST: The log file path is: " + EasyLogger.LogFile);

            InitializeComponent();
        }
        private void OpacitySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            EasyLogger.Info("Setting background opacity to: " + Default.WindowOpacity);

            Default.WindowOpacity = OpacitySlider.Value;

            window.Background.Opacity = OpacitySlider.Value;
            windowBackground.Opacity  = OpacitySlider.Value;

            if (OpacitySlider.Value < 0.95)
            {
                Overlay.Opacity = 0.1;
            }
            else
            {
                Overlay.Opacity = 0.3;
            }
        }
Beispiel #20
0
        public static DialogResult MessageForm(string text, string title = null, MessageBoxButtons buttons = MessageBoxButtons.OK, MessageBoxIcon icon = MessageBoxIcon.Information, MessageBoxDefaultButton defaultButton = MessageBoxDefaultButton.Button2)
        {
            try
            {
                // Log this message for debugging
                if (icon == MessageBoxIcon.Error)
                {
                    EasyLogger.Error(text);
                }
                else if (icon == MessageBoxIcon.Warning)
                {
                    EasyLogger.Info(text);
                }
                else
                {
                    EasyLogger.Info(text);
                }

                using (Form form = new Form())
                {
                    form.Opacity = 0;

                    form.Show();

                    form.WindowState = FormWindowState.Minimized;

                    form.WindowState = FormWindowState.Normal;

                    DialogResult dialogResult = MessageBox.Show(form, text, title, buttons, icon, defaultButton);
                    if (dialogResult == DialogResult.Yes)
                    {
                        form.Close();
                    }
                    return(dialogResult);
                }
            }
            catch (Exception ex)
            {
                EasyLogger.Error(ex);

                return(DialogResult.None);
            }
        }
        public void DateTimeSettings()
        {
            timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate
            {
                if (Default.ShowDate)
                {
                    ShowDateCheckBox.IsChecked = true;
                    CurrentDate.Content        = DateTime.Now.ToString(@"dddd, MMM d");

                    ShowDateCheckBox.Checked   += ShowDateCheckBox_Checked;
                    ShowDateCheckBox.Unchecked += ShowDateCheckBox_Unchecked;
                }
                if (Default.ShowTime)
                {
                    ShowTimeCheckBox.IsChecked = true;
                    CurrentTime.Content        = DateTime.Now.ToString(@"h:mm tt");

                    ShowTimeCheckBox.Checked   += ShowTimeCheckBox_Checked;
                    ShowTimeCheckBox.Unchecked += ShowTimeCheckBox_Unchecked;
                }
                if (UpdateTimer.ReturnDateTime(DateTime.Now.AddMinutes(-30), FileTime) && !Updating && ConnectedToInternet)
                {
                    Updating = true;

                    EasyLogger.Info("Downloading new weather info using values: " + Default.LatValue + "," + Default.LongValue);

                    Thread thread = new Thread(() => DesktopWeatherXML(PreWeatherString + Default.LatValue + "," + Default.LongValue, NWSAlertsDirectory + "\\WeatherInfo.xml"))
                    {
                        IsBackground = true
                    };
                    thread.Start();
                }
                if (UpdateTimer.ReturnDateTime(DateTime.Now.AddMinutes(-10), AlertTime))
                {
                    AlertTime = DateTime.Now.AddSeconds(-DateTime.Now.Second);

                    if (CheckForInternet.Connected())
                    {
                        ParseWeatherXML.NWSAlertsInfo();
                    }
                }
            }, Dispatcher);
        }
Beispiel #22
0
 private void Proc_ErrorReceived(object sender, DataReceivedEventArgs e)
 {
     try
     {
         if (e.Data != null)
         {
             if (e.Data != string.Empty)
             {
                 string Output = Regex.Replace(e.Data, "\x00", "");
                 EasyLogger.Info(Output);
                 BeginInvoke(new MethodInvoker(() => Console(Output)));
             }
         }
     }
     catch (Exception ex)
     {
         EasyLogger.Error(ex + Environment.NewLine);
         BeginInvoke(new MethodInvoker(() => Console(ex.Message)));
     }
 }
Beispiel #23
0
        private async Task <string> FollowAsync()
        {
            string response = null;

            Follow twitter = new Follow(_API_KEY, _ACCESS_TOKEN, _API_SECRET_KEY, _ACCESS_TOKEN_SECRET, _BEARER_TOKEN);

            response = await Task.Run(() => twitter.FollowAsync(_SCREEN_NAME));

            if (response != "OK")
            {
                EasyLogger.Warning(response);

                MessageBox.Show(response, "Social Post Scheduler", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                EasyLogger.Info("Requested message posted successfully!");
            }

            return("OK");
        }
        public void DesktopWeatherXML(string url, string savePath)
        {
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                try
                {
                    XDocument xml = XDocument.Load(url);

                    xml.Save(savePath);
                }
                catch (Exception ex)
                {
                    ConnectedToInternet = false;

                    EasyLogger.Info("It appears that you do not have an internet connection. We will retry later. The actual error message is: " + Environment.NewLine + Environment.NewLine + "     " + ex.Message + Environment.NewLine);
                }

                if (File.Exists(NWSAlertsDirectory + "\\WeatherInfo.xml"))
                {
                    EasyLogger.Info("New weather information downloaded and saved successfully");

                    fileInfo = new FileInfo(NWSAlertsDirectory + "\\WeatherInfo.xml");

                    FileTime = fileInfo.LastWriteTime;
                }
                else
                {
                    EasyLogger.Info("It appears you are not connected to the internet. Please check your internet connection and try again.");

                    MessageBox.Show("It appears you are not connected to the internet. Please check your internet connection and try again.", "NWS Alerts", MessageBoxButton.OK, MessageBoxImage.Information);

                    NotifyTray.notifyIcon.Visible = false;

                    Environment.Exit(0);
                }

                SetWeatherUI();
            }));
        }
        // Disable Sceduled Tasks
        static void DisableSetTask(string taskname)
        {
            ProcessStartInfo start = new ProcessStartInfo();

            start.FileName               = "schtasks.exe";
            start.UseShellExecute        = false;
            start.CreateNoWindow         = true;
            start.WindowStyle            = ProcessWindowStyle.Hidden;
            start.Arguments              = "/query /TN " + "\"" + taskname + "\"";
            start.RedirectStandardOutput = true;

            using (Process process = Process.Start(start))
            {
                using (StreamReader reader = process.StandardOutput)
                {
                    string stdout = reader.ReadToEnd();
                    if (stdout.Contains(taskname))
                    {
                        if (stdout.Contains("Ready"))
                        {
                            EasyLogger.Info("Disabling task: " + taskname);

                            ProcessStartInfo info = new ProcessStartInfo();
                            info.FileName               = "schtasks.exe";
                            info.UseShellExecute        = false;
                            info.CreateNoWindow         = true;
                            info.WindowStyle            = ProcessWindowStyle.Hidden;
                            info.Arguments              = "/change /TN " + "\"" + taskname + "\"" + " /DISABLE";
                            info.RedirectStandardOutput = true;
                            using (Process proc = Process.Start(info))
                            {
                                proc.WaitForExit();
                            }
                        }
                    }
                }
            }
        }
Beispiel #26
0
 public static void MessageLogging(string text, string title = null, MessageBoxButtons buttons = MessageBoxButtons.OK, MessageBoxIcon icon = MessageBoxIcon.Information, MessageBoxDefaultButton defaultButton = MessageBoxDefaultButton.Button2)
 {
     try
     {
         // Log this message for debugging
         if (icon == MessageBoxIcon.Error)
         {
             EasyLogger.Error(text);
         }
         else if (icon == MessageBoxIcon.Warning)
         {
             EasyLogger.Info(text);
         }
         else
         {
             EasyLogger.Info(text);
         }
     }
     catch (Exception ex)
     {
         EasyLogger.Error(ex);
     }
 }
        public static void DeleteSetFiles()
        {
            // Delete Files and Folders in a Directory
            foreach (string paths in Default.PathFilesToDelete)
            {
                try
                {
                    if (Directory.Exists(paths))
                    {
                        var filesPath = Environment.ExpandEnvironmentVariables(paths);

                        // Files
                        foreach (string file in Directory.GetFiles(filesPath))
                        {
                            bool deleted = false;
                            try
                            {
                                File.Delete(file);
                                deleted = true;
                            }
                            catch (Exception ex)
                            {
                                deleted = false;
                                EasyLogger.Error(file + " : " + ex);
                                continue;
                            }
                            if (deleted)
                            {
                                EasyLogger.Info("Deleting file: " + file);
                            }
                        }

                        // Directories
                        foreach (string directory in Directory.GetDirectories(filesPath))
                        {
                            bool deleted = false;
                            try
                            {
                                Directory.Delete(directory, true);
                                deleted = true;
                            }
                            catch (Exception ex)
                            {
                                deleted = false;
                                EasyLogger.Error(directory + " : " + ex);
                                continue;
                            }
                            if (deleted)
                            {
                                EasyLogger.Info("Deleting directory: " + directory);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    EasyLogger.Error(paths + " : " + ex);
                    continue;
                }
            }
        }
Beispiel #28
0
        // Delete Files and Folders in a Directory older than x days
        public static void DeleteSetFiles()
        {
            foreach (string path in Default.PathFilesToDeleteOlder)
            {
                try
                {
                    int days      = Convert.ToInt32(path.Split(',')[0]);
                    var filesPath = Environment.ExpandEnvironmentVariables(path.Split(',')[1].Trim());

                    // Files
                    foreach (string f in Directory.GetFiles(filesPath, "*", SearchOption.AllDirectories))
                    {
                        bool deleted = false;
                        try
                        {
                            FileInfo fi = new FileInfo(f);
                            if (fi.LastWriteTime < DateTime.Now.AddDays(-days))
                            {
                                File.Delete(f);
                                deleted = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            deleted = false;
                            EasyLogger.Error(f + " : " + ex);
                            continue;
                        }
                        if (deleted)
                        {
                            EasyLogger.Info("Deleting file: " + f);
                        }
                    }

                    // Directories
                    string[] dirs = Directory.GetDirectories(filesPath, "*", SearchOption.AllDirectories);
                    foreach (string d in dirs)
                    {
                        bool deleted = false;
                        try
                        {
                            DirectoryInfo fi = new DirectoryInfo(d);
                            if (fi.LastWriteTime < DateTime.Now.AddDays(-days))
                            {
                                try
                                {
                                    Directory.Delete(d, false);
                                    deleted = true;
                                }
                                catch
                                {
                                    continue;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            deleted = false;
                            EasyLogger.Error(d + " : " + ex);
                            continue;
                        }
                        if (deleted)
                        {
                            EasyLogger.Info("Deleting file: " + d);
                        }
                    }
                }
                catch (Exception ex)
                {
                    EasyLogger.Error(path + " : " + ex);
                    continue;
                }
            }
        }
Beispiel #29
0
        private static void StartLightCleanup()
        {
            if (Default.DeleteBrokenShortcuts)
            {
                EasyLogger.Info("*********************  Delete Broken Shortcuts  *********************" + Environment.NewLine);
                BrokenShortcuts.Remove();
            }
            if (Default.InvalidFirewallBox)
            {
                EasyLogger.Info("*********************  Remove Invalid Firewall Rules  *********************" + Environment.NewLine);
                WindowsFirewall.DeleteInvalid();
            }

            if (Default.InvalidVariablesBox)
            {
                EasyLogger.Info("*********************  Remove Invalid Environment Variables  *********************" + Environment.NewLine);
                WindowsVariables.DeleteInvalid();
            }

            if (Default.TasksToDisable.Count > 0)
            {
                EasyLogger.Info("*********************  Disable Scheduled Tasks  *********************" + Environment.NewLine);
                DisableTasks.SetTasks();
            }

            if (Default.ServicesToManual.Count > 0 || Default.ServicesToDisable.Count > 0)
            {
                EasyLogger.Info("*********************  Unused Services To Manual  *********************" + Environment.NewLine);
                SetServices.SetStatus();
            }

            if (Default.FilesToHide.Count > 0)
            {
                EasyLogger.Info("*********************  Set Files to Hidden  *********************" + Environment.NewLine);
                HideFiles.SetAsHidden();
            }

            if (Default.PathFilesToDelete.Count > 0)
            {
                EasyLogger.Info("*********************  Delete Files In Directory  *********************" + Environment.NewLine);
                DeleteInDirectory.DeleteSetFiles();
            }

            if (Default.PathFilesToDeleteOlder.Count > 0)
            {
                EasyLogger.Info("*********************  Delete Files in Directory Older  *********************" + Environment.NewLine);
                DeleteInDirectoryOlder.DeleteSetFiles();
            }

            if (Default.FilesToDelete.Count > 0)
            {
                EasyLogger.Info("*********************  Delete Specific Files  *********************" + Environment.NewLine);
                DeleteFiles.DeleteSetFiles();
            }

            if (Default.DirectoriesToDelete.Count > 0)
            {
                EasyLogger.Info("*********************  Delete Specific Directories  *********************" + Environment.NewLine);
                DeleteDirectories.DeleteSetPaths();
            }
        }
Beispiel #30
0
        static void Main(string[] args)
        {
            if (Default.LoggingEnabled)
            {
                EasyLogger.BackupLogs(EasyLogger.LogFile, 30);
                EasyLogger.AddListener(EasyLogger.LogFile);
            }

            if (Default.UpgradeRequired)
            {
                Default.Upgrade();
                Default.UpgradeRequired = false;
                Default.Save();
                Default.Reload();
            }
            if (Default.FirstRun)
            {
                Default.FirstRun = false;
                Default.Save();
                Default.Reload();

                SettingsForm settings = new SettingsForm();
                settings.ShowDialog();

                Environment.Exit(0);
            }

            if (args.Length > 0)
            {
                try
                {
                    string A0 = args[0].ToLower();

                    if (args[0] == "/optimize" || args[0] == "-optimize")
                    {
                        StartLightCleanup();
                    }
                    else
                    {
                        StartLightCleanup();
                    }
                }
                catch (Exception ex)
                {
                    EasyLogger.Info(ex.Message);
                }
            }
            else
            {
                // Run Settings and Close
                SettingsForm settings = new SettingsForm();
                settings.ShowDialog();
            }

            EasyLogger.Info("*********************  END OF OPTIMIZATIONS  *********************");

            EasyLogger.RemoveListener();

#if DEBUG
            using (StreamReader sr = File.OpenText(EasyLogger.LogFile))
            {
                string lines = sr.ReadToEnd();

                if (lines.ToLower().Contains("[error]"))
                {
                    MessageBox.Show("The log file contains errors!", "Maintenance", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    Process.Start(EasyLogger.LogDirectory);
                }
            }
#endif

            Environment.Exit(0);
        }