예제 #1
0
 private static void SystemEventsSessionEnding(object sender, SessionEndingEventArgs e)
 {
     SystemEvents.SessionEnding -= SystemEventsSessionEnding;
     Desktop.SaveIconPositions();
 }
예제 #2
0
        private void CheckDrivesTimerTick(object sender, EventArgs e)
        {
            try
            {
                if (_checking)
                {
                    return;
                }
                _checking = true;

                // Additions...
                foreach (var drive in DriveInfo.GetDrives())
                {
                    try
                    {
                        if (DriveIncluded(drive) && drive.IsReady)
                        {
                            var name = GetDriveName(drive);

                            if (_shortcuts.Contains(name))
                            {
                                continue;
                            }

                            var desktopShortcutPath = DesktopShortcutPath(name + DriveInformation(drive));
                            Shell.CreateShortcut(desktopShortcutPath, drive.RootDirectory.FullName);
                            _shortcuts.Add(new Shortcut(desktopShortcutPath, drive.RootDirectory.FullName, name, drive.DriveType));
                            var location = Desktop.WaitForShortcut(name);
                            if (location == null)
                            {
                                continue;
                            }

                            if (Settings.Default.RememberIconPositions)
                            {
                                location = Desktop.LoadIconPosition(name) ?? location;
                                Desktop.SetIconPosition(name, (Point)location);
                            }

                            if (Settings.Default.MinimizeAll)
                            {
                                Shell.MinimizeAll();
                            }

                            if (Settings.Default.Locus)
                            {
                                Effects.ShowEffect(this, (Point)location);
                            }

                            if (Settings.Default.OpenExplorer)
                            {
                                NativeMethods.ShellExecute(IntPtr.Zero, "explore", desktopShortcutPath,
                                                           "", "", NativeMethods.ShowCommands.SW_SHOWDEFAULT);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Program.LogError(ex.Message);
                    }
                }

                try
                {
                    // Subtractions
                    foreach (var shortcut in new List <Shortcut>(_shortcuts))
                    {
                        if (!Directory.Exists(shortcut.RootDirectoryPath) ||
                            !DriveIncluded(new DriveInfo(shortcut.RootDirectoryPath.Substring(0, 1))))
                        {
                            Desktop.SaveIconPosition(shortcut.Name, Desktop.GetIconPosition(shortcut.Name));
                            SafeFileDelete(shortcut.DesktopShortcutPath);
                            _shortcuts.Remove(shortcut.Name);
                        }
                    }
                }
                catch (InvalidOperationException ex)
                {
                    Program.LogError(ex.Message);
                }
            }
            finally
            {
                _checking = false;
                SetWorkingSetSize();
            }
        }