Esempio n. 1
0
        private void RemoveInvalidEntries()
        {
            List <string> groupNames = ShortcutUtil.GetShortcutGroupNames();

            foreach (string groupName in groupNames)
            {
                bool updated = false;
                List <ShortcutItem> shortcuts = ShortcutUtil.GetShortcuts(groupName);
                for (int i = shortcuts.Count - 1; i >= 0; i--)
                {
                    ShortcutItem item        = shortcuts[i];
                    string       application = item.Application;
                    string       txt         = item.Text;
                    if (!System.IO.Directory.Exists(application) && !System.IO.File.Exists(application))
                    {
                        //invalid
                        WriteLine(string.Format("removing: {0}", txt));
                        WriteLine(string.Format("   {0}", application));
                        shortcuts.RemoveAt(i);
                        updated = true;
                    }
                }

                //update shortcuts if necessary
                if (updated)
                {
                    ShortcutUtil.UpdateGroupShortcut(groupName, shortcuts.ToArray());
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Reassign Shortcut Id. In the event where Ids are corrupted.
        /// </summary>
        private void AssignShortcutIds()
        {
            List <string> groupNames = ShortcutUtil.GetShortcutGroupNames();

            foreach (string groupName in groupNames)
            {
                List <ShortcutItem> shortcuts = ShortcutUtil.GetShortcuts(groupName);
                foreach (ShortcutItem item in shortcuts)
                {
                    string newId = Guid.NewGuid().ToString();
                    WriteLine(string.Format("{0}: {1}", groupName, item.Text));
                    WriteLine(string.Format("   {0} => {1}", item.Id, newId));
                    item.Id = newId;
                }
                ShortcutUtil.UpdateGroupShortcut(groupName, shortcuts.ToArray());
            }
        }
Esempio n. 3
0
        private void FixApplicationPaths()
        {
            List <string> groupNames = ShortcutUtil.GetShortcutGroupNames();

            foreach (string groupName in groupNames)
            {
                List <ShortcutItem> shortcuts = ShortcutUtil.GetShortcuts(groupName);
                foreach (ShortcutItem item in shortcuts)
                {
                    string applicationPath = item.Application;
                    if (applicationPath.StartsWith("\""))
                    {
                        item.Application = GetApplicationPart(applicationPath);
                    }
                }
                ShortcutUtil.UpdateGroupShortcut(groupName, shortcuts.ToArray());
            }
        }
Esempio n. 4
0
        /// <summary>
        /// <para>Created By    : YUKUANG</para>
        /// <para>Created Date  : 15 Oct 2009</para>
        /// <para>Modified By   : -</para>
        /// <para>Modified Date : -</para>
        /// <para>---------------------------------------------------------------</para>
        /// <para></para>
        /// <para>Changes</para>
        /// <para>---------------------------------------------------------------</para>
        /// <para></para>
        /// <para>Description</para>
        /// <para>---------------------------------------------------------------</para>
        /// For rebuilding of icons for older release of the Shortcut Manager.
        /// It will extract icons and patch up the shortcut files
        /// </summary>
        private void RebuildIcons()
        {
            WriteLine("Getting Group Name Config");

            DeleteUnmappedIcons();

            List <string> groupNames = ShortcutUtil.GetShortcutGroupNames();

            foreach (string groupName in groupNames)
            {
                List <ShortcutItem> shortcuts = ShortcutUtil.GetShortcuts(groupName);
                foreach (ShortcutItem item in shortcuts)
                {
                    string applicationPath = item.Application;
                    if (applicationPath.EndsWith(".exe") && System.IO.File.Exists(applicationPath))
                    {
                        //Try to extract the icon file
                        try
                        {
                            Write(string.Format("Extracting Icon: {0}", applicationPath));
                            IconExtractor extractor = new IconExtractor(applicationPath);

                            //Gets the first icon in the Executable
                            System.Drawing.Icon ico = extractor.GetIcon(0);

                            //create unique name
                            string uniqueFilename = System.IO.Path.GetFileNameWithoutExtension(applicationPath);
                            string iconPath       = System.IO.Path.Combine(AppConfig.IconFolder, uniqueFilename + ".ico");
                            string uniqueIconPath = MakeUniqueFilename(iconPath);

                            bool isNonUnique = !uniqueIconPath.Equals(iconPath);

                            //Save the Icon using a FileStream
                            using (System.IO.FileStream fs = new System.IO.FileStream(uniqueIconPath, System.IO.FileMode.OpenOrCreate))
                            {
                                ico.Save(fs);
                                fs.Close();
                                fs.Dispose();
                            }
                            WriteLine("\tExtracted\n");



                            if (isNonUnique)
                            {
                                //non-unique file path detected. check if it's same bytes
                                WriteLine("Non unique icon found. Checking hashcode.");

                                byte[] b1 = System.IO.File.ReadAllBytes(uniqueIconPath);
                                byte[] b2 = System.IO.File.ReadAllBytes(iconPath);

                                int s1 = System.Convert.ToBase64String(b1).GetHashCode();
                                int s2 = System.Convert.ToBase64String(b2).GetHashCode();

                                WriteLine(string.Format("  {0} vs {1}", s1, s2));
                                if (s1 == s2)
                                {
                                    WriteLine("Deleting duplicate.");
                                    System.IO.File.Delete(uniqueIconPath);
                                    uniqueIconPath = iconPath;
                                }
                            }

                            //Patch the datarow
                            item.IconPath = System.IO.Path.GetFileName(uniqueIconPath);
                        }
                        catch (Exception)
                        {
                            //display error
                            MessageBox.Show(
                                "Unable to extract icon for [" + groupName + "/" + item.Text + "]",
                                "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                ShortcutUtil.UpdateGroupShortcut(groupName, shortcuts.ToArray());
            }
        }