Example #1
0
        private void MiSC_ChangeICO_Click(object sender, RoutedEventArgs e)
        {
            MenuItem    mi = (MenuItem)sender;
            ContextMenu cm = (ContextMenu)mi.Parent;
            Shortcut    sc = cm.PlacementTarget as Shortcut;

            string[] iconsourcefiles = new string[] {
                // provide a path to the original icon
                sc.lnkData.ShortcutAddress,
                sc.lnkData.OriginalTargetPath,
                Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\shell32.dll"),
                Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\imageres.dll"),
                Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\DDORes.dll")
            };

            using (IconSelect iconSelector = new IconSelect()
            {
                Owner = this
            })
            {
                iconSelector.IconSelectSetIconSourcePaths(iconsourcefiles);

                // if the user selected something so the value is not false or null for retruned bool?
                if (true == iconSelector.ShowDialog())
                {
                    //var x = iconSelector.DialogResult;
                    sc.lnkData.IconIndex          = iconSelector.idxIcon;
                    sc.lnkData.IconSourceFilePath = iconsourcefiles[iconSelector.idxFile];

                    // set the new icon
                    IconBitMap ibm = null;
                    if (sc.lnkData.IconIndex != USE_MAIN_ICON)
                    {
                        ibm = ico2bmap.ExtractICO(sc.lnkData.IconSourceFilePath, sc.lnkData.IconIndex);
                    }
                    if (null == ibm)
                    {
                        ibm = ico2bmap.ExtractIconBitMap(System.Drawing.Icon.ExtractAssociatedIcon(sc.lnkData.IconSourceFilePath));
                    }
                    sc.Source = ibm.bitmapsource;
                    sc.Width  = ibm.BitmapSize;
                }
            }
        }
Example #2
0
        private void Dlg_Drop(object sender, DragEventArgs eDropEvent)
        {
            // init base code
            //base.OnDrop(eDropEvent);  // do not use this code does all needed

            //string[] dataFormats = eDropEvent.Data.GetFormats(true);

            // If the DataObject contains string data, extract it.
            if (eDropEvent.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] FileList = (string[])eDropEvent.Data.GetData(DataFormats.FileDrop, false);

                CreateShortCuts(FileList);
                PlaceShortcutsintoView();

                eDropEvent.Handled = true;
            }
            else if (eDropEvent.Data.GetDataPresent(SC_DROP_FORMAT))
            {
                ShortcutDropData sdd      = (ShortcutDropData)eDropEvent.Data.GetData(SC_DROP_FORMAT);
                Shortcut         s        = sdd._parent.Children[sdd._idx] as Shortcut;
                string[]         FileList = new string[] { s.lnkData.ShortcutAddress };

                // a drop onto the icon also sets off a drop onto a dialog - do not reproduce the icon
                var items = Shortcuts.Where(x => x.lnkData.ShortcutAddress == FileList[0]);
                if (items.Count() == 0)
                {
                    CreateShortCuts(FileList);
                    PlaceShortcutsintoView();

                    // remove the shortcut from the parent panel before pacing it here
                    ((KO_Dialog)sdd._parent.Parent).DeleteShortcut(s);
                    //MainPanel.Children.Add(s);
                }

                eDropEvent.Handled = true;
            }
            else
            {
                eDropEvent.Handled = false;
            }
        }
Example #3
0
        private void SC_mouseMove(object sender, MouseEventArgs e)
        {
            // Get the current mouse position
            System.Windows.Point mousePos = e.GetPosition(null);
            Vector diff = startPoint - mousePos;

            if (e.LeftButton == MouseButtonState.Pressed &&
                (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
                 Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
            {
                // Get the dragged item
                Shortcut sc = sender as Shortcut;
                if (MainPanel.Children.Contains(sc))
                {
                    // Can just pass its index or the whole object
                    //int sourceidx = MainPanel.Children.IndexOf(sc);
                    ShortcutDropData sdd = new ShortcutDropData(MainPanel.Children.IndexOf(sc), sc.Parent as UniformGrid);
                    //DataObject dragData = new DataObject(SC_DROP_FORMAT, sc);
                    DataObject dragData = new DataObject(SC_DROP_FORMAT, sdd); // sourceidx);
                    DragDrop.DoDragDrop(sc, dragData, DragDropEffects.Move);   //  DragDropEffects.Copy);
                }
            }
        }
Example #4
0
        private void RunShortcut(Shortcut scLink)
        {
            try
            {
                if (scLink != null)
                {
                    try
                    {
                        Process p = null;

                        // This is this a reference .appref-ms file or an URL or a data file
                        if (scLink.lnkData.bTargetIsFile || scLink.lnkData.bIsReference)
                        {
                            //if( scLink.lnkData.bIsReference ) {
                            //string n = @"rundll32.exe dfshim.dll,ShOpenVerbApplication http://github-windows.s3.amazonaws.com/GitHub.application#GitHub.application,Culture=neutral,PublicKeyToken=317444273a93ac29,processorArchitecture=x86";
                            //rundll32.exe dfshim.dll,ShOpenVerbShortcut D:\Users\User\Desktop\GitHub
                            //Uri a = new Uri(n);
                            //string b = a.ToString(); }

                            p = Process.Start(scLink.lnkData.ShortcutAddress);  // just send the link to the OS
                        }
                        else
                        {
                            // Prepare the process to run
                            ProcessStartInfo start = new ProcessStartInfo();
                            // Enter in the command line arguments, everything you would enter after the executable name itself
                            if (scLink.lnkData.bTargetIsDirectory)
                            {
                                start.Arguments        = scLink.lnkData.TargetPath;
                                start.FileName         = "explorer.exe";
                                start.WorkingDirectory = scLink.lnkData.TargetPath;
                            }
                            else
                            {
                                start.Arguments = scLink.lnkData.Arguments;
                                // Enter the executable to run, including the complete path
                                start.FileName = scLink.lnkData.TargetPath;
                                /// For cases where the starting working directory is like this:  Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");
                                start.WorkingDirectory = string.Empty; //Environment.ExpandEnvironmentVariables(scLink.lnkData.WorkingDirectory);
                                //start.WorkingDirectory = System.IO.Path.GetFullPath(scLink.lnkData.WorkingDirectory);
                            }
                            // Do you want to show a console window?
                            start.WindowStyle     = ProcessWindowStyle.Normal;
                            start.CreateNoWindow  = true;
                            start.UseShellExecute = false; // do not open reference using shell or args can not be used

                            /// Run the programm
                            ///
                            try
                            {
                                p = Process.Start(start);
                            }
                            catch (Exception e)
                            {
                                lnkio.WriteProgramLog(e.Message);

                                /// if the process fails it seems that the current working directory may be to blame
                                /// For example: The GitBash shortcut uses as command args: "C:\Program Files\Git\git-bash.exe" --cd-to-home
                                /// and the starting working directory of %HOMEDRIVE%%HOMEPATH% (use Environment.ExpandEnvironmentVariables)
                                start.WorkingDirectory = string.Empty;//@"D:\Users\user";
                                try
                                {
                                    p = Process.Start(start);
                                }
                                catch (Exception e1)
                                {
                                    lnkio.WriteProgramLog(e1.Message);
                                    //throw new Exception("Program run error: Program start failed");
                                }
                            }
                        }

                        if (p == null) // could be that it just does not start 2+ instances
                        {
                            // throw new Exception("Program run error: Program did not run");
                        }
                    }
                    catch (Exception e)
                    {
                        lnkio.WriteProgramLog(e.Message);
                        //throw new Exception("Program run error: Program start failed");
                    }

                    //int exitCode;
                    //// Run the external process & wait for it to finish
                    //using (Process proc = Process.Start(start))
                    //{
                    //    proc.WaitForExit();

                    //    // Retrieve the app's exit code
                    //    exitCode = proc.ExitCode;
                    //}
                }
                else
                {
                    // bad
                    if (scLink != null)
                    {
                        if (scLink.Name != null)
                        {
                            throw new Exception("Program run error: Internal data lookup error. The icon has no data or internal name: '" + scLink.Name + "' is corrupt");
                        }
                        else
                        {
                            throw new Exception("Program run error: Internal data lookup error. The icon internal name is missing");
                        }
                    }
                    else
                    {
                        throw new Exception("Program run error: Internal shortcut data lookup error. The data is not found");
                    }
                }
            }
            catch (Exception e)
            {
                lnkio.WriteProgramLog(e.Message);
                //throw new Exception("Program run error: Unknown internal error. Program data lookup failed.");
            }
            //mouseEvent.Handled = true;
            return;
        }
Example #5
0
        /// <summary>
        /// Drop an icon onto another switching the positions with each other
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SC_drop(object sender, DragEventArgs e)
        {
            try
            {
                //string[] dataFormats = e.Data.GetFormats(true);

                // If the DataObject contains the correct format, extract the info and move the icons
                if (e.Data.GetDataPresent(SC_DROP_FORMAT))
                {
                    ShortcutDropData sdd        = (ShortcutDropData)e.Data.GetData(SC_DROP_FORMAT);
                    Shortcut         TargetIcon = (Shortcut)e.OriginalSource;

                    if (sdd._parent == TargetIcon.Parent)
                    {
                        Shortcut SourceIcon = (Shortcut)MainPanel.Children[sdd._idx];

                        //Shortcut trg = (Shortcut)this.InputHitTest(e.GetPosition(this));
                        if (TargetIcon != SourceIcon)
                        {
                            // remove the shortcut from the list, the panel and destroy itself
                            if (SourceIcon != null && MainPanel.Children.Contains(SourceIcon))
                            {
                                // must be removed first before inserting it with new index
                                int Source_idx = MainPanel.Children.IndexOf(SourceIcon);
                                int Target_idx = MainPanel.Children.IndexOf(TargetIcon);

                                DeleteShortcut(TargetIcon);
                                MainPanel.Children.Insert(Source_idx, TargetIcon);
                                Shortcuts.Add(TargetIcon);

                                DeleteShortcut(SourceIcon);
                                MainPanel.Children.Insert(Target_idx, SourceIcon);
                                Shortcuts.Add(SourceIcon);

                                // delete the icon with the lowest index
                                //if (Source_idx > Target_idx)
                                //{
                                //    //DeleteShortcut(TargetIcon);
                                //    MainPanel.Children.Insert
                                //}
                                //else
                                //{
                                //    DeleteShortcut(SourceIcon);
                                //}

                                //if (MainPanel.Children.Count < Target_idx)
                                //    MainPanel.Children.Add(SourceIcon);
                                //else
                                //    MainPanel.Children.Insert(Target_idx, SourceIcon);

                                //if (MainPanel.Children.Count < Source_idx)
                                //    MainPanel.Children.Add(TargetIcon);
                                //else
                                //   MainPanel.Children.Insert(Source_idx, TargetIcon);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lnkio.WriteProgramLog(ex.Message);
                //throw new Exception(ex.Message);
            }
            //finally{}//throw new NotImplementedException();
        }
Example #6
0
        /// <summary>
        /// Create the KickOff link
        /// </summary>
        /// <param name="FileList"></param>
        private void CreateShortCuts(string[] FileList)
        {
            foreach (string shortcutini in FileList)
            {
                if (null == shortcutini || string.Empty == shortcutini)
                {
                    continue;
                }

                /// Check if a sub dialog is being defined
                /// If so create a new dialog
                ///



                /// The shortcut file names may be a path to a link file or target file/directory
                /// or it may be that and a user selected icon source and index separated using
                /// a split character
                string   iconFilePath = string.Empty;
                int      iconIndex    = USE_MAIN_ICON;
                string   FilePath     = string.Empty;
                string[] sc_args      = null;
                try {
                    sc_args  = shortcutini.Split(INI_SPLIT_CHAR);
                    FilePath = Environment.ExpandEnvironmentVariables(sc_args[0]);
                    if (sc_args.Length == 3)
                    {
                        iconFilePath = Environment.ExpandEnvironmentVariables(sc_args[1]);
                        iconIndex    = int.Parse(sc_args[2]);
                    }
                    else if (sc_args.Length != 1)
                    {
                        WriteProgramLog("Kickoff.ini read error. Shortcut dataset should be 1 or 3 items and is " + sc_args.Length.ToString());
                    }
                    else
                    {
                        iconFilePath = sc_args[0]; // set icon path to the link file
                    }
                }
                catch (Exception e)
                {
                    WriteProgramLog(FilePath + " Error: " + e.Message);
                    // screwed up so move on
                    continue;
                }

                // expand the paths
                //FilePath = Environment.ExpandEnvironmentVariables(FilePath);
                //iconFilePath = Environment.ExpandEnvironmentVariables(iconFilePath);

                /// Test here that FilePath, iconFilePath, iconIndex have sane values and point to something
                ///
                if (!System.IO.File.Exists(FilePath))
                {
                    if (!System.IO.Directory.Exists(FilePath))
                    {
                        //System.IO.File.GetAttributes(FilePath).HasFlag(FileAttributes.Directory);
                        WriteProgramLog(FilePath +
                                        ": Windows thinks this is not a file or directory path.\n\tCould be a permissions/security issue."
                                        );
                        // screwed up move on
                        continue;
                    }
                }

                // path to icons could be a direstory if the target is a directory
                if (!System.IO.File.Exists(iconFilePath))
                {
                    if (!System.IO.Directory.Exists(iconFilePath))
                    {
                        WriteProgramLog(iconFilePath +
                                        ": Windows thinks this is not a file or directory path.\n\tCould be an invalid path or permissions/security issue."
                                        );
                        // reassign the icon source
                        iconFilePath = FilePath;
                    }
                }

                //if (iconIndex == 0) iconIndex = USE_MAIN_ICON;
                //else
                if (iconIndex < USE_MAIN_ICON || iconIndex > ico2bmap.MAX_ICONS)
                {
                    WriteProgramLog("Icon index: " + sc_args[2].ToString() + " is an invalid value");
                    iconIndex = USE_MAIN_ICON;
                }

                LnkData lnk = lnkio.ResolveShortcut(FilePath, iconFilePath, iconIndex);
                if (null != lnk)
                {
                    if (null == lnk || lnk.ShortcutAddress == string.Empty)
                    {
                        WriteProgramLog("Shortcut link does not have a path:" + FilePath);
                        //throw new Exception("Shortcut link does not have a path");
                    }

                    Shortcut sc = new Shortcut
                    {
                        lnkData    = lnk,
                        lnkPopup   = new Popup(),
                        IsRendered = false
                    };

                    var items = Shortcuts.Where(x => x.lnkData.ShortcutAddress == FilePath);

                    if (items.Count() == 0) // the link imported is not in the existing list so add it
                    {
                        /// Add the shortcut to the list
                        Shortcuts.Add(sc);
                    }
                }
            }
        }
Example #7
0
        /// <summary>
        /// Create the KickOff link
        /// </summary>
        /// <param name="FileList"></param>
        private void CreateShortCuts(string[] FileList)
        {
            foreach (string shortcutini in FileList)
            {
                if (null == shortcutini || string.Empty == shortcutini)
                    continue;

                /// The shortcut file names may be a path to a link file or target file/directory
                /// or it may be that and a user selected icon source and index separated using 
                /// a split character
                string iconFilePath=string.Empty;
                int iconIndex = USE_MAIN_ICON;
                string FilePath = string.Empty;
                string[] sc_args = null;
                try {
                    sc_args = shortcutini.Split(INI_SPLIT_CHAR);
                    FilePath = Environment.ExpandEnvironmentVariables(sc_args[0]);
                    if (sc_args.Length == 3)
                    {
                        iconFilePath = Environment.ExpandEnvironmentVariables(sc_args[1]);
                        iconIndex = int.Parse(sc_args[2]);
                    }
                    else if (sc_args.Length != 1)
                    {
                        WriteProgramLog("Kickoff.ini read error. Shortcut dataset should be 1 or 3 items and is " + sc_args.Length.ToString());
                    }
                    else
                        iconFilePath = sc_args[0]; // set icon path to the link file
                }
                catch (Exception e)
                {
                    WriteProgramLog(FilePath + " Error: " + e.Message);
                    // screwed up so move on
                    continue;
                }

                // expand the paths
                //FilePath = Environment.ExpandEnvironmentVariables(FilePath);
                //iconFilePath = Environment.ExpandEnvironmentVariables(iconFilePath);

                /// Test here that FilePath, iconFilePath, iconIndex have sane values and point to something
                /// 
                if (!System.IO.File.Exists(FilePath) )
                {
                    if (!System.IO.Directory.Exists(FilePath))
                    {
                        //System.IO.File.GetAttributes(FilePath).HasFlag(FileAttributes.Directory);
                        WriteProgramLog(FilePath +
                            ": Windows thinks this is not a file or directory path.\n\tCould be a permissions/security issue."
                            );
                        // screwed up move on
                        continue;
                    }
                }

                // path to icons could be a direstory if the target is a directory
                if (!System.IO.File.Exists(iconFilePath))
                {
                    if (!System.IO.Directory.Exists(iconFilePath))
                    {
                        WriteProgramLog(iconFilePath +
                            ": Windows thinks this is not a file or directory path.\n\tCould be an invalid path or permissions/security issue."
                            );
                        // reassign the icon source
                        iconFilePath = FilePath;
                    }
                }

                //if (iconIndex == 0) iconIndex = USE_MAIN_ICON;
                //else 
                if (iconIndex < USE_MAIN_ICON || iconIndex > ico2bmap.MAX_ICONS)
                {
                    WriteProgramLog("Icon index: " + sc_args[2].ToString() + " is an invalid value");
                    iconIndex = USE_MAIN_ICON;
                }

                LnkData lnk = lnkio.ResolveShortcut(FilePath, iconFilePath, iconIndex);
                if (null != lnk)
                {
                    if( null == lnk || lnk.ShortcutAddress == string.Empty)
                    {
                        WriteProgramLog("Shortcut link does not have a path:" + FilePath);
                        //throw new Exception("Shortcut link does not have a path");
                    }

                    Shortcut sc = new Shortcut
                    {
                        lnkData = lnk,
                        lnkPopup = new Popup(),
                        IsRendered = false
                    };

                    var items = Shortcuts.Where(x => x.lnkData.ShortcutAddress == FilePath);

                    if (items.Count() == 0) // the link imported is not in the existing list so add it
                    {
                        /// Add the shortcut to the list
                        Shortcuts.Add(sc);
                    }
                }
            }
        }
Example #8
0
        private void RunShortcut(Shortcut scLink)
        {
            try
            {
                if (scLink != null)
                {
                    try
                    {
                        Process p = null;

                        // This is this a reference .appref-ms file or an URL or a data file
                        if (scLink.lnkData.bTargetIsFile || scLink.lnkData.bIsReference)
                        {
                            //if( scLink.lnkData.bIsReference ) {
                            //string n = @"rundll32.exe dfshim.dll,ShOpenVerbApplication http://github-windows.s3.amazonaws.com/GitHub.application#GitHub.application,Culture=neutral,PublicKeyToken=317444273a93ac29,processorArchitecture=x86";
                            //rundll32.exe dfshim.dll,ShOpenVerbShortcut D:\Users\User\Desktop\GitHub
                            //Uri a = new Uri(n);
                            //string b = a.ToString(); }

                            p = Process.Start(scLink.lnkData.ShortcutAddress);  // just send the link to the OS
                        }
                        else
                        {
                            // Prepare the process to run
                            ProcessStartInfo start = new ProcessStartInfo();
                            // Enter in the command line arguments, everything you would enter after the executable name itself
                            if (scLink.lnkData.bTargetIsDirectory)
                            {
                                start.Arguments = scLink.lnkData.TargetPath;
                                start.FileName = "explorer.exe";
                                start.WorkingDirectory = scLink.lnkData.TargetPath;
                            }
                            else
                            {
                                start.Arguments = scLink.lnkData.Arguments;
                                // Enter the executable to run, including the complete path
                                start.FileName = scLink.lnkData.TargetPath;
                                /// For cases where the starting working directory is like this:  Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");
                                start.WorkingDirectory = string.Empty; //Environment.ExpandEnvironmentVariables(scLink.lnkData.WorkingDirectory);
                                //start.WorkingDirectory = System.IO.Path.GetFullPath(scLink.lnkData.WorkingDirectory);
                            }
                            // Do you want to show a console window?
                            start.WindowStyle = ProcessWindowStyle.Normal;
                            start.CreateNoWindow = true;
                            start.UseShellExecute = false; // do not open reference using shell or args can not be used

                            /// Run the programm
                            /// 
                            try
                            {
                                p = Process.Start(start);
                            }
                            catch (Exception e)
                            {
                                lnkio.WriteProgramLog(e.Message);

                                /// if the process fails it seems that the current working directory may be to blame
                                /// For example: The GitBash shortcut uses as command args: "C:\Program Files\Git\git-bash.exe" --cd-to-home
                                /// and the starting working directory of %HOMEDRIVE%%HOMEPATH% (use Environment.ExpandEnvironmentVariables)
                                start.WorkingDirectory = string.Empty;//@"D:\Users\user";
                                try
                                {
                                    p = Process.Start(start);
                                }
                                catch (Exception e1)
                                {
                                    lnkio.WriteProgramLog(e1.Message);
                                    //throw new Exception("Program run error: Program start failed");
                                }
                            }
                        }

                        if (p == null) // could be that it just does not start 2+ instances
                        {
                            // throw new Exception("Program run error: Program did not run");
                        }
                    }
                    catch (Exception e)
                    {
                        lnkio.WriteProgramLog(e.Message);
                        //throw new Exception("Program run error: Program start failed");
                    }

                    //int exitCode;
                    //// Run the external process & wait for it to finish
                    //using (Process proc = Process.Start(start))
                    //{
                    //    proc.WaitForExit();

                    //    // Retrieve the app's exit code
                    //    exitCode = proc.ExitCode;
                    //}
                }
                else
                {
                    // bad
                    if (scLink != null)
                    {
                        if (scLink.Name != null)
                            throw new Exception("Program run error: Internal data lookup error. The icon has no data or internal name: '" + scLink.Name + "' is corrupt");
                        else
                            throw new Exception("Program run error: Internal data lookup error. The icon internal name is missing");
                    }
                    else
                        throw new Exception("Program run error: Internal shortcut data lookup error. The data is not found");
                }
            }
            catch (Exception e)
            {
                lnkio.WriteProgramLog(e.Message);
                //throw new Exception("Program run error: Unknown internal error. Program data lookup failed.");
            }
            //mouseEvent.Handled = true;
            return;
        }
Example #9
0
 private void DeleteShortcut(Shortcut sc)
 {
     try
     {
         // remove the shortcut from the list, the panel and destroy itself
         if (sc != null && MainPanel.Children.Contains(sc))
         {
             // Deleting an object requires anything that may 
             // reference it like events to be doing this 
             // need to be cleared
             sc.Triggers.Clear();
             int target = MainPanel.Children.IndexOf(sc);
             MainPanel.Children.Remove(sc);
             
             // Delete the shortcut from the internal list
             Shortcuts.Remove(sc);
         }
     }
     catch (Exception ex)
     {
         lnkio.WriteProgramLog(ex.Message);
         //throw new Exception(ex.Message);
     }
 }