Esempio n. 1
0
        public static T FindChild <T>(DependencyObject parentObj) where T : DependencyObject
        {
            if (parentObj == null)
            {
                return(null);
            }

            try
            {
                if (parentObj is T)
                {
                    return(parentObj as T);
                }

                for (int i = 0; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(parentObj); i++)
                {
                    T childObj = FindChild <T>(System.Windows.Media.VisualTreeHelper.GetChild(parentObj, i));
                    if (childObj != null)
                    {
                        return(childObj);
                    }
                }
            }
            catch (Exception err)
            {
                AppLog.Exception(err);
            }
            return(null);
        }
Esempio n. 2
0
 public static string parsePath(string path)
 {
     try
     {
         if (path.Contains(@"\device\mup\"))
         {
             return(@"\" + path.Substring(11, path.Length - 11));
         }
         string[] strArray = path.Split(new char[1] {
             '\\'
         }, StringSplitOptions.RemoveEmptyEntries);
         string vol = @"\" + strArray[0] + @"\" + strArray[1];
         path = path.Replace(vol, GetDriveLetter(vol));
         if (path.Contains('~'))
         {
             path = Path.GetFullPath(path);
         }
         return(path);
     }
     catch (Exception err)
     {
         AppLog.Exception(err);
     }
     return("");
 }
Esempio n. 3
0
        static public bool MoveFile(string from, string to, bool Overwrite = false)
        {
            try
            {
                if (File.Exists(to))
                {
                    if (!Overwrite)
                    {
                        return(false);
                    }
                    File.Delete(to);
                }

                File.Move(from, to);

                if (File.Exists(from))
                {
                    return(false);
                }
            }
            catch (Exception err)
            {
                AppLog.Exception(err);
                return(false);
            }
            return(true);
        }
Esempio n. 4
0
        public static string SID_SPLevel        = "S-1-16-28672"; //	Secure Process Mandatory Level

        public static bool TakeOwn(string path)
        {
            bool ret = true;

            try
            {
                TokenManipulator.AddPrivilege(TokenManipulator.SE_TAKE_OWNERSHIP_NAME);

                FileSecurity ac = File.GetAccessControl(path);
                ac.SetOwner(new SecurityIdentifier(FileOps.SID_Admins));
                File.SetAccessControl(path, ac);
            }
            catch (Exception err)
            {
                AppLog.Exception(err);
                ret = false;
            }
            finally
            {
                TokenManipulator.RemovePrivilege(TokenManipulator.SE_TAKE_OWNERSHIP_NAME);
            }
            return(ret);
        }
Esempio n. 5
0
 public static bool Exec(string cmd, string args, bool hidden = true)
 {
     try
     {
         Process process = new Process();
         process.StartInfo.UseShellExecute = false;
         if (hidden)
         {
             process.StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
             process.StartInfo.CreateNoWindow = true;
         }
         process.StartInfo.FileName  = cmd;
         process.StartInfo.Arguments = args;
         process.StartInfo.Verb      = "runas"; // run as admin
         process.Start();
         process.WaitForExit();
         return(true);
     }
     catch (Exception err)
     {
         AppLog.Exception(err);
     }
     return(false);
 }
Esempio n. 6
0
        private UwpFunc.AppInfo GetInfo(Windows.ApplicationModel.Package package, string sid)
        {
            string path;

            try
            {
                path = package.InstalledLocation.Path;
            }
            catch
            {
                return(null);
            }

            string manifest = Path.Combine(path, "AppxManifest.xml");

            if (!File.Exists(manifest))
            {
                return(null);
            }

            XElement xelement;

            try
            {
                string manifestXML = File.ReadAllText(manifest);

                int startIndex = manifestXML.IndexOf("<Properties>", StringComparison.Ordinal);
                int num        = manifestXML.IndexOf("</Properties>", StringComparison.Ordinal);
                xelement = XElement.Parse(manifestXML.Substring(startIndex, num - startIndex + 13).Replace("uap:", string.Empty));
            }
            catch (Exception err)
            {
                AppLog.Exception(err);
                return(null);
            }

            string displayName = null;
            string logoPath    = null;

            try
            {
                displayName = xelement.Element((XName)"DisplayName")?.Value;
                logoPath    = xelement.Element((XName)"Logo")?.Value;
            }
            catch (Exception err)
            {
                AppLog.Exception(err);
            }

            if (displayName == null)
            {
                return(null);
            }

            try
            {
                Uri result;
                if (Uri.TryCreate(displayName, UriKind.Absolute, out result))
                {
                    string pathToPri         = Path.Combine(package.InstalledLocation.Path, "resources.pri");
                    string resourceKey1      = "ms-resource://" + package.Id.Name + "/resources/" + ((IEnumerable <string>)result.Segments).Last <string>();
                    string stringFromPriFile = MiscFunc.GetResourceStr(pathToPri, resourceKey1);
                    if (!string.IsNullOrEmpty(stringFromPriFile.Trim()))
                    {
                        displayName = stringFromPriFile;
                    }
                    else
                    {
                        string str          = string.Concat(((IEnumerable <string>)result.Segments).Skip <string>(1));
                        string resourceKey2 = "ms-resource://" + package.Id.Name + "/" + str;
                        stringFromPriFile = MiscFunc.GetResourceStr(pathToPri, resourceKey2);
                        if (!string.IsNullOrEmpty(stringFromPriFile.Trim()))
                        {
                            displayName = stringFromPriFile;
                        }
                    }
                }

                if (logoPath != null)
                {
                    string path1 = Path.Combine(package.InstalledLocation.Path, logoPath);
                    if (File.Exists(path1))
                    {
                        logoPath = path1;
                    }
                    else
                    {
                        string path2 = Path.Combine(package.InstalledLocation.Path, Path.ChangeExtension(path1, "scale-100.png"));
                        if (File.Exists(path2))
                        {
                            logoPath = path2;
                        }
                        else
                        {
                            string path3 = Path.Combine(Path.Combine(package.InstalledLocation.Path, "en-us"), logoPath);
                            string path4 = Path.Combine(package.InstalledLocation.Path, Path.ChangeExtension(path3, "scale-100.png"));
                            if (File.Exists(path4))
                            {
                                logoPath = path4;
                            }
                            else
                            {
                                logoPath = null;
                            }
                        }
                    }
                }
            }
            catch (Exception err)
            {
                AppLog.Exception(err);
            }

            return(new UwpFunc.AppInfo()
            {
                Name = displayName, Logo = logoPath, ID = package.Id.FamilyName, SID = sid
            });
        }
Esempio n. 7
0
        private UwpFunc.AppInfo GetInfo(Windows.ApplicationModel.Package package)
        {
            string path;
            string manifest;

            try
            {
                path = package.InstalledLocation.Path; // that call takes a long time

                manifest = Path.Combine(path, !package.IsBundle ? @"AppxManifest.xml" : @"AppxMetadata\AppxBundleManifest.xml");
                if (!File.Exists(manifest))
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }

            XElement xelement;

            try
            {
                string manifestXML = File.ReadAllText(manifest);

                int startIndex = manifestXML.IndexOf("<Properties>", StringComparison.Ordinal);
                int num        = manifestXML.IndexOf("</Properties>", StringComparison.Ordinal);
                xelement = XElement.Parse(manifestXML.Substring(startIndex, num - startIndex + 13).Replace("uap:", string.Empty));
            }
            catch (Exception err)
            {
                AppLog.Exception(err);
                return(null);
            }

            string displayName = null;
            string logoPath    = null;

            try
            {
                displayName = xelement.Element((XName)"DisplayName")?.Value;
                logoPath    = xelement.Element((XName)"Logo")?.Value;
            }
            catch (Exception err)
            {
                AppLog.Exception(err);
            }

            if (displayName == null)
            {
                return(null);
            }

            try
            {
                Uri result;
                if (Uri.TryCreate(displayName, UriKind.Absolute, out result))
                {
                    string pathToPri         = Path.Combine(path, "resources.pri");
                    string resourceKey1      = "ms-resource://" + package.Id.Name + "/resources/" + ((IEnumerable <string>)result.Segments).Last <string>();
                    string stringFromPriFile = MiscFunc.GetResourceStr(pathToPri, resourceKey1);
                    if (!string.IsNullOrEmpty(stringFromPriFile.Trim()))
                    {
                        displayName = stringFromPriFile;
                    }
                    else
                    {
                        string str          = string.Concat(((IEnumerable <string>)result.Segments).Skip <string>(1));
                        string resourceKey2 = "ms-resource://" + package.Id.Name + "/" + str;
                        stringFromPriFile = MiscFunc.GetResourceStr(pathToPri, resourceKey2);
                        if (!string.IsNullOrEmpty(stringFromPriFile.Trim()))
                        {
                            displayName = stringFromPriFile;
                        }
                    }
                }

                if (logoPath != null)
                {
                    List <string> extensions = new List <string> {
                        "", "scale-100.png", "scale-125.png", "scale-150.png", "scale-200.png", "scale-400.png"
                    };
                    List <string> sub_dirs = new List <string> {
                        "", "en-us"
                    };

                    string foundPath = null;
                    foreach (string extension in extensions)
                    {
                        foreach (string sub_dir in sub_dirs)
                        {
                            string testPath = path;
                            if (sub_dir.Length > 0)
                            {
                                testPath = Path.Combine(testPath, sub_dir);
                            }

                            string testName = logoPath;
                            if (extension.Length > 0)
                            {
                                testName = Path.ChangeExtension(testName, extension);
                            }

                            testPath = Path.Combine(testPath, testName);
                            if (File.Exists(testPath))
                            {
                                foundPath = testPath;
                                goto done;
                            }
                        }
                    }

done:
                    logoPath = foundPath;
                }
            }
            catch (Exception err)
            {
                AppLog.Exception(err);
            }

            return(new UwpFunc.AppInfo()
            {
                Name = displayName, Logo = logoPath, ID = package.Id.FamilyName, Path = path
            });
        }