예제 #1
0
        private void StackMenu_Drop(object sender, DragEventArgs e)
        {
            Menu            dropContainer = sender as Menu;
            SystemDirectory replacedDir   = dropContainer.DataContext as SystemDirectory;

            string[] fileNames = e.Data.GetData(DataFormats.FileDrop) as string[];
            if (fileNames != null)
            {
                foreach (string fileName in fileNames)
                {
                    if (StacksManager.Instance.AddLocation(fileName))
                    {
                        int dropIndex = StacksManager.Instance.StackLocations.IndexOf(replacedDir);
                        StacksManager.Instance.StackLocations.Move(StacksManager.Instance.StackLocations.Count - 1, dropIndex);
                    }
                }
            }
            else if (e.Data.GetDataPresent(typeof(SystemDirectory)))
            {
                SystemDirectory dropData = e.Data.GetData(typeof(SystemDirectory)) as SystemDirectory;

                int initialIndex = StacksManager.Instance.StackLocations.IndexOf(dropData);
                int dropIndex    = StacksManager.Instance.StackLocations.IndexOf(replacedDir);
                StacksManager.Instance.StackLocations.Move(initialIndex, dropIndex);
            }

            e.Handled = true;
        }
예제 #2
0
        private void StackMenu_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (!inMove && startPoint != null && !ctxOpen)
            {
                inMove = true;

                Point  mousePos = e.GetPosition(this);
                Vector diff     = (Point)startPoint - mousePos;

                if (mousePos.Y <= this.ActualHeight && ((Point)startPoint).Y <= this.ActualHeight && e.LeftButton == MouseButtonState.Pressed && (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
                {
                    Menu            menu        = sender as Menu;
                    SystemDirectory selectedDir = menu.DataContext as SystemDirectory;

                    try
                    {
                        DragDrop.DoDragDrop(menu, selectedDir, DragDropEffects.Move);
                    }
                    catch { }

                    // reset the stored mouse position
                    startPoint = null;

                    e.Handled = true;
                }

                inMove = false;
            }
        }
예제 #3
0
        public DesktopIcons()
        {
            InitializeComponent();

            String desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            if (Directory.Exists(desktopPath))
            {
                SystemDirectory desktopSysDir = new SystemDirectory(desktopPath, Dispatcher.CurrentDispatcher);
                Locations.Add(desktopSysDir);
            }
        }
예제 #4
0
        public static void PerformDirectoryAction(string action, SystemDirectory directory, Window window)
        {
            switch (action)
            {
            case DirectoryActions.New:
                window.Activate();
                // watch for new file to be created so we can perform an action
                directory.FileCreated += ShellNew_FileCreated;
                break;

            case DirectoryActions.Paste:
                directory.PasteFromClipboard();
                break;
            }
        }
        public StacksContainer()
        {
            InitializeComponent();
            // Sets the Theme for Cairo
            string theme = Properties.Settings.Default.CairoTheme;

            if (theme != "Cairo.xaml")
            {
                ResourceDictionary CairoDictionary = (ResourceDictionary)XamlReader.Load(System.Xml.XmlReader.Create(AppDomain.CurrentDomain.BaseDirectory + theme));
                this.Resources.MergedDictionaries[0] = CairoDictionary;
            }
            try
            {
                this.deserialize();
            }
            catch {}

            Locations.CollectionChanged += new NotifyCollectionChangedEventHandler(locations_CollectionChanged);

            // Add some default folders on FirstRun
            if (Properties.Settings.Default.IsFirstRun == true)
            {
                // Check for Documents Folder
                String myDocsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                if (Directory.Exists(myDocsPath))
                {
                    SystemDirectory myDocsSysDir = new SystemDirectory(myDocsPath, Dispatcher.CurrentDispatcher);
                    // Don't duplicate defaults
                    if (!Locations.Contains(myDocsSysDir))
                    {
                        Locations.Add(myDocsSysDir);
                    }
                }
                // Check for Downloads folder
                String downloadsPath = System.Environment.GetEnvironmentVariable("USERPROFILE") + @"\Downloads";
                if (Directory.Exists(downloadsPath))
                {
                    SystemDirectory downloadsSysDir = new SystemDirectory(downloadsPath, Dispatcher.CurrentDispatcher);
                    // Don't duplicate defaults
                    if (!Locations.Contains(downloadsSysDir))
                    {
                        Locations.Add(downloadsSysDir);
                    }
                }
            }
        }
예제 #6
0
        private void locationDisplay_Drop(object sender, DragEventArgs e)
        {
            string[] fileNames = e.Data.GetData(DataFormats.FileDrop) as string[];
            if (fileNames != null)
            {
                foreach (string fileName in fileNames)
                {
                    StacksManager.Instance.AddLocation(fileName);
                }
            }
            else if (e.Data.GetDataPresent(typeof(SystemDirectory)))
            {
                SystemDirectory dropData = e.Data.GetData(typeof(SystemDirectory)) as SystemDirectory;

                int initialIndex = StacksManager.Instance.StackLocations.IndexOf(dropData);
                StacksManager.Instance.StackLocations.Move(initialIndex, StacksManager.Instance.StackLocations.Count - 1);
            }

            e.Handled = true;
        }
예제 #7
0
        public DesktopIcons()
        {
            InitializeComponent();
            // Sets the Theme for Cairo
            string theme = Properties.Settings.Default.CairoTheme;

            if (theme != "Cairo.xaml")
            {
                ResourceDictionary CairoDictionary = (ResourceDictionary)XamlReader.Load(System.Xml.XmlReader.Create(AppDomain.CurrentDomain.BaseDirectory + theme));
                this.Resources.MergedDictionaries[0] = CairoDictionary;
            }

            String desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            if (Directory.Exists(desktopPath))
            {
                SystemDirectory desktopSysDir = new SystemDirectory(desktopPath, Dispatcher.CurrentDispatcher);
                Locations.Add(desktopSysDir);
            }
        }
예제 #8
0
        private void btnFile_Drop(object sender, DragEventArgs e)
        {
            if (!currentlyRenaming)
            {
                string[] fileNames = e.Data.GetData(DataFormats.FileDrop) as string[];
                if (e.Data.GetDataPresent(typeof(SystemFile)))
                {
                    SystemFile dropData = e.Data.GetData(typeof(SystemFile)) as SystemFile;
                    fileNames = new string[] { dropData.FullName };
                }

                if (fileNames != null)
                {
                    if (file.IsDirectory)
                    {
                        SystemDirectory destDirectory = new SystemDirectory(file.FullName, Dispatcher);
                        if (isDropMove)
                        {
                            destDirectory.MoveInto(fileNames);
                        }
                        else
                        {
                            destDirectory.CopyInto(fileNames);
                        }
                    }
                    else
                    {
                        if (isDropMove)
                        {
                            file.ParentDirectory?.MoveInto(fileNames);
                        }
                        else
                        {
                            file.ParentDirectory?.CopyInto(fileNames);
                        }
                    }

                    e.Handled = true;
                }
            }
        }
예제 #9
0
        private static List <string> FetchStartupApps()
        {
            List <string> startupApps = new List <string>();

            // HKLM Run
            foreach (string keyString in hklmStartupKeys)
            {
                RegistryKey key;

                key = Registry.LocalMachine.OpenSubKey(keyString, false);

                if (key != null && key.ValueCount > 0)
                {
                    foreach (string valueName in key.GetValueNames())
                    {
                        startupApps.Add(((string)key.GetValue(valueName)).Replace("\"", ""));
                    }
                }

                if (key != null)
                {
                    key.Close();
                }
            }

            // HKCU Run
            foreach (string keyString in hkcuStartupKeys)
            {
                RegistryKey key;

                if (keyString.Contains("RunOnce"))
                {
                    key = Registry.CurrentUser.OpenSubKey(keyString, true);
                }
                else
                {
                    key = Registry.CurrentUser.OpenSubKey(keyString, false);
                }

                if (key != null && key.ValueCount > 0)
                {
                    foreach (string valueName in key.GetValueNames())
                    {
                        startupApps.Add(((string)key.GetValue(valueName)).Replace("\"", ""));

                        // if this is a runonce key, remove the value after we grab it
                        if (keyString.Contains("RunOnce"))
                        {
                            try
                            {
                                key.DeleteValue(valueName);
                            }
                            catch { }
                        }
                    }
                }

                if (key != null)
                {
                    key.Close();
                }
            }

            // Common Start Menu - Startup folder
            SystemDirectory comStartupDir = new SystemDirectory(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartup), Dispatcher.CurrentDispatcher);

            foreach (SystemFile startupFile in comStartupDir.Files)
            {
                startupApps.Add(startupFile.FullName);
            }

            // Start Menu - Startup folder
            SystemDirectory startupDir = new SystemDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Startup), Dispatcher.CurrentDispatcher);

            foreach (SystemFile startupFile in startupDir.Files)
            {
                startupApps.Add(startupFile.FullName);
            }

            return(startupApps);
        }
예제 #10
0
        private void SetDesktopDir(string desktopDir)
        {
            SystemDirectory desktop = new SystemDirectory(desktopDir, Dispatcher.CurrentDispatcher);

            Locations.Add(desktop);
        }
예제 #11
0
        private static List <string> FetchStartupApps()
        {
            List <string> startupApps = new List <string>();

            // Registry startup keys
            Dictionary <string, string> startupKeys = new Dictionary <string, string>()
            {
                {
                    "Software\\Microsoft\\Windows\\CurrentVersion\\Run",
                    "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved\\Run"
                },
                {
                    "Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run",
                    "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved\\Run32"
                },
                {
                    "Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce",
                    ""
                }
            };

            // TODO: foreach(RegistryKey root in new[] { Registry.LocalMachine ,Registry.CurrentUser}) ... Would this be a more readable solution ???
            // loop twice, once for HKLM once for HKCU
            for (int i = 0; i <= 1; i++)
            {
                foreach (KeyValuePair <string, string> regKey in startupKeys)
                {
                    bool isRunOnce = regKey.Key.Contains("RunOnce");

                    RegistryKey root        = null; // HKLM or HKCU
                    RegistryKey key         = null; // AppPath
                    RegistryKey approvedKey = null; // the startupapproved key tells us if the item is disabled

                    try
                    {
                        if (i == 0)
                        {
                            root = Registry.LocalMachine;
                        }
                        else
                        {
                            root = Registry.CurrentUser;
                        }

                        if (isRunOnce && i != 0)
                        {
                            key = root.OpenSubKey(regKey.Key, true);
                        }
                        else if (isRunOnce)
                        {
                            continue; // skip processing HKLM RunOnce because we can't remove things from there
                        }
                        else
                        {
                            key         = root.OpenSubKey(regKey.Key, false);
                            approvedKey = root.OpenSubKey(regKey.Value, false);
                        }
                    }
                    catch
                    {
                        continue; // in case of unable to load registry key
                    }

                    if (key != null && key.ValueCount > 0)
                    {
                        foreach (string valueName in key.GetValueNames())
                        {
                            bool canRun = true;

                            if (approvedKey != null)
                            {
                                foreach (string approvedName in approvedKey.GetValueNames())
                                {
                                    try
                                    {
                                        string s = ((byte[])approvedKey.GetValue(approvedName))[0].ToString();
                                        if (approvedName == valueName && ((byte[])approvedKey.GetValue(approvedName))[0] % 2 != 0) // if value is odd number, item is disabled
                                        {
                                            canRun = false;
                                            break;
                                        }
                                        else if (approvedName == valueName)
                                        {
                                            break;
                                        }
                                    }
                                    catch { } // in case of invalid registry key values
                                }
                            }

                            if (canRun)
                            {
                                startupApps.Add(((string)key.GetValue(valueName)).Replace("\"", ""));
                            }

                            // if this is a runonce key, remove the value after we grab it
                            if (isRunOnce)
                            {
                                try
                                {
                                    key.DeleteValue(valueName);
                                }
                                catch { }
                            }
                        }
                    }

                    if (key != null)
                    {
                        key.Close();
                    }

                    if (approvedKey != null)
                    {
                        approvedKey.Close();
                    }
                }
            }

            // startup folders
            Dictionary <string, RegistryKey> startupFolderKeys = new Dictionary <string, RegistryKey>()
            {
                {
                    Environment.GetFolderPath(Environment.SpecialFolder.CommonStartup),
                    Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved\\StartupFolder", false)
                },
                {
                    Environment.GetFolderPath(Environment.SpecialFolder.Startup),
                    Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved\\StartupFolder", false)
                }
            };

            foreach (KeyValuePair <string, RegistryKey> startupFolder in startupFolderKeys)
            {
                try
                {
                    if (Shell.Exists(startupFolder.Key))
                    {
                        SystemDirectory directory = new SystemDirectory(startupFolder.Key, Dispatcher.CurrentDispatcher);
                        foreach (SystemFile startupFile in directory.Files)
                        {
                            bool canRun = true;

                            if (startupFolder.Value != null)
                            {
                                foreach (string approvedName in startupFolder.Value.GetValueNames())
                                {
                                    try
                                    {
                                        string s = ((byte[])startupFolder.Value.GetValue(approvedName))[0].ToString();
                                        if (approvedName == startupFile.Name && ((byte[])startupFolder.Value.GetValue(approvedName))[0] % 2 != 0) // if value is odd number, item is disabled
                                        {
                                            canRun = false;
                                            break;
                                        }
                                        else if (approvedName == startupFile.Name)
                                        {
                                            break;
                                        }
                                    }
                                    catch { } // in case of invalid registry key values
                                }
                            }

                            if (canRun)
                            {
                                startupApps.Add(startupFile.FullName);
                            }
                        }

                        directory.Dispose();
                    }
                }
                catch
                {
                    CairoLogger.Instance.Info("Failed to run startup apps from location:" + startupFolder.Key);
                }
            }

            return(startupApps);
        }
예제 #12
0
 public void SetIconLocation()
 {
     Location = new SystemDirectory(desktopManager.NavigationManager.CurrentPath,
                                    Dispatcher.CurrentDispatcher);
 }