Esempio n. 1
0
        public static ImageSource GetIcon(string path, double size)
        {
            string key = path + "@" + size.ToString();

            ImageSource image = null;

            IconCacheLock.EnterReadLock();
            bool bFound = IconCache.TryGetValue(key, out image);

            IconCacheLock.ExitReadLock();
            if (bFound)
            {
                return(image);
            }

            try
            {
                var pathIndex = TextHelpers.Split2(path, "|");

                IconExtractor extractor = new IconExtractor(pathIndex.Item1);
                int           index     = MiscFunc.parseInt(pathIndex.Item2);
                if (index < extractor.Count)
                {
                    image = ToImageSource(extractor.GetIcon(index, new System.Drawing.Size((int)size, (int)size)));
                }

                if (image == null)
                {
                    if (File.Exists(MiscFunc.NtOsKrnlPath)) // if running in WOW64 this does not exist
                    {
                        image = ToImageSource(Icon.ExtractAssociatedIcon(MiscFunc.NtOsKrnlPath));
                    }
                    else // fall back to an other icon
                    {
                        image = ToImageSource(Icon.ExtractAssociatedIcon(MiscFunc.Shell32Path));
                    }
                }

                image.Freeze();
            }
            catch (Exception err)
            {
                //AppLog.Exception(err);
            }

            IconCacheLock.EnterWriteLock();
            if (!IconCache.ContainsKey(key))
            {
                IconCache.Add(key, image);
            }
            IconCacheLock.ExitWriteLock();
            return(image);
        }
Esempio n. 2
0
        //////////////////////////////////////////////////////////////////////////////////////////////
        // App resource handling


        public string GetAppResourceStr(string resourcePath)
        {
            // Note: PackageManager requirers admin privilegs

            var AppResource = TextHelpers.Split2(resourcePath.Substring(2, resourcePath.Length - 3), "?");
            var package     = packageManager.FindPackage(AppResource.Item1);

            if (package != null)
            {
                string pathToPri = Path.Combine(package.InstalledLocation.Path, "resources.pri");
                return(MiscFunc.GetResourceStr(pathToPri, AppResource.Item2));
            }

            return(resourcePath);
        }
Esempio n. 3
0
        public static WinVer Parse(string Str)
        {
            WinVer winVer = new WinVer();

            try
            {
                List <string> tokens = TextHelpers.SplitStr(Str, "|");
                foreach (string token in tokens)
                {
                    var VerVal = TextHelpers.Split2(token, "=");
                    if (VerVal.Item1 == "minVer")
                    {
                        winVer.minVer = float.Parse(VerVal.Item2);
                    }
                    else if (VerVal.Item1 == "maxVer")
                    {
                        winVer.maxVer = float.Parse(VerVal.Item2);
                    }

                    // win 10
                    else if (VerVal.Item1 == "build")
                    {
                        winVer.build10 = int.Parse(VerVal.Item2);
                    }
                    else if (VerVal.Item1 == "buildMax")
                    {
                        winVer.build10max = int.Parse(VerVal.Item2);
                    }
                    else if (VerVal.Item1 == "winEd")
                    {
                        winVer.win10Ed = (Edition10)Enum.Parse(typeof(Edition10), VerVal.Item2);
                    }
                }
            }
            catch {
                return(null);
            }

            return(winVer.minVer != 0.0 ? winVer : null);
        }
Esempio n. 4
0
        public bool Restore(string state)
        {
            var           stateTemp = TextHelpers.Split2(state, "#"); // in case we want to add some more info
            List <string> State     = TextHelpers.SplitStr(stateTemp.Item1, "|", true);

            if (State.Count != dataGrid.Columns.Count)
            {
                return(false);
            }

            Hold = true;
            for (int i = 0; i < dataGrid.Columns.Count; i++)
            {
                var Column = dataGrid.Columns[i];
                if (State[i].Length == 0)
                {
                    Column.Visibility = Visibility.Collapsed;
                }
                else
                {
                    Column.Visibility = Visibility.Visible;

                    var PosWidth = TextHelpers.Split2(State[i], ";");

                    int Pos = MiscFunc.parseInt(PosWidth.Item1, -1);
                    if (Pos == -1)
                    {
                        continue;
                    }

                    Column.DisplayIndex = Pos;
                    Column.Width        = new DataGridLength(MiscFunc.parseInt(PosWidth.Item2, 50));
                }
            }
            Hold = false;

            CreateHeaderMenu();
            return(true);
        }