Example #1
0
        public override TLauncherEntry ReadLinkFile(string file)
        {
            var ini   = new INIFile(file);
            var entry = new TLauncherEntry();

            entry.Name = ini.GetValue("Desktop Entry", "Name", "");
            var cmd = ini.GetValue("Desktop Entry", "Exec", "");

            entry.CommandPath = Path.GetDirectoryName(cmd);
            entry.CommandFile = Path.GetFileName(cmd);
            entry.CommandArgs = "";             //TODO
            entry.Categories  = ini.GetValue("Desktop Entry", "Categories", "");
            entry.IconName    = ini.GetValue("Desktop Entry", "Icon", "");
            entry.Description = ini.GetValue("Desktop Entry", "Comment", "");
            entry.UpdateMainCategory();
            return(entry);
        }
Example #2
0
        public static void SetCategory(TLauncherEntry entry)
        {
            if (xdoc == null)
            {
                xdoc = XDocument.Load("../res/categories/default.xml");
            }

            foreach (var itm in  xdoc.Root.Elements("Item"))
            {
                var filter = itm.Attribute("Filter").Value;
                var cat    = itm.Attribute("Category").Value;
                if (entry.Command.ToLower().Contains(filter))
                {
                    entry.Categories = cat;
                    entry.UpdateMainCategory();
                    return;
                }
                entry.Categories   = "None";
                entry.MainCategory = "None";
            }
        }
Example #3
0
        public static TLauncherEntry CreateFromFileLnk(string path)
        {
            var entry = new TLauncherEntry();

            string name, command, args, description, iconLocation;
            int    iconIndex;

            ResolveShortcut(path, out name, out command, out args, out description, out iconLocation, out iconIndex);

            command = Environment.ExpandEnvironmentVariables(command);

            if (!File.Exists(command))
            {
                var newCommand = command.Replace("\\Program Files (x86)", "\\Program Files").Replace("\\system32", "\\Sysnative");
                if (File.Exists(newCommand))
                {
                    command = newCommand;
                }
                else
                {
                    CoreLib.Log("COMMAND NOT FOUND: '" + command + "'");
                }
            }

            if (string.IsNullOrEmpty(iconLocation))
            {
                iconLocation = command;
                iconIndex    = 0;
            }

            //if (name == "Steam") {
            //	AppLib.log("########################################################" + iconLocation);
            //}

            iconLocation = Environment.ExpandEnvironmentVariables(iconLocation);

            if (!File.Exists(iconLocation))
            {
                //AppLib.log("COMMAND NOT FOUND: " + command);
                iconLocation = iconLocation.Replace("\\Program Files (x86)", "\\Program Files").Replace("\\system32", "\\Sysnative");
            }

            if (File.Exists(iconLocation))
            {
                //var ext = new TsudaKageyu.IconExtractor(iconLocation);
                //var ico = ext.GetIcon(iconIndex);

                IntPtr p1 = new IntPtr();
                IntPtr p2 = new IntPtr();
                Interop.ExtractIconEx(iconLocation, iconIndex, ref p1, ref p2, 1);

                System.Drawing.Icon ico;
                if (p1 != IntPtr.Zero)
                {
                    ico = System.Drawing.Icon.FromHandle(p1);
                }
                else
                {
                    ico = System.Drawing.Icon.FromHandle(p2);
                }

                var ms = new MemoryStream();
                ico.ToBitmap().Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                entry.IconStored = ms.ToArray();
            }
            else
            {
                CoreLib.Log("ICON LOCATION NOT FOUND: " + iconLocation);
            }

            if (path.Contains("ANNO"))
            {
                var s = "";
            }

            entry.Name        = name;
            entry.CommandPath = Path.GetDirectoryName(command);
            entry.CommandFile = Path.GetFileName(command);
            entry.CommandArgs = args;
            entry.Description = description;

            SetCategory(entry);

            return(entry);
        }