private static string GetAbsStr(Guid guid, string relStr, bool isName) { string absStr = relStr; if (isName) { if (!absStr.StartsWith("@")) { return(absStr); } else { absStr = absStr.Substring(1); } if (absStr.StartsWith("{*?ms-resource://") && absStr.EndsWith("}")) { absStr = "@{" + UwpHelper.GetPackageName(GetUwpName(guid)) + absStr.Substring(2); return(absStr); } } string filePath = GetFilePath(guid); if (filePath == null) { return(relStr); } string dirPath = Path.GetDirectoryName(filePath); if (absStr.StartsWith("*")) { absStr = filePath + absStr.Substring(1); } else if (absStr.StartsWith(".\\")) { absStr = dirPath + absStr.Substring(1); } else if (absStr.StartsWith("..\\")) { do { dirPath = Path.GetDirectoryName(dirPath); absStr = absStr.Substring(3); } while(absStr.StartsWith("..\\")); absStr = dirPath + "\\" + absStr; } if (isName) { absStr = "@" + absStr; } return(absStr); }
public static string GetFilePath(Guid guid) { string filePath = null; if (guid.Equals(Guid.Empty)) { return(filePath); } if (FilePathDic.ContainsKey(guid)) { filePath = FilePathDic[guid]; } else { string uwpName = GetUwpName(guid); if (!string.IsNullOrEmpty(uwpName)) { filePath = UwpHelper.GetFilePath(uwpName, guid); } else { foreach (string clsidPath in ClsidPaths) { using (RegistryKey guidKey = RegistryEx.GetRegistryKey($@"{clsidPath}\{guid:B}")) { if (guidKey == null) { continue; } foreach (string keyName in new[] { "InprocServer32", "LocalServer32" }) { using (RegistryKey key = guidKey.OpenSubKey(keyName)) { if (key == null) { continue; } string value1 = key.GetValue("CodeBase")?.ToString().Replace("file:///", "").Replace('/', '\\'); if (File.Exists(value1)) { filePath = value1; break; } string value2 = key.GetValue("")?.ToString(); value2 = ObjectPath.ExtractFilePath(value2); if (File.Exists(value2)) { filePath = value2; break; } } } if (File.Exists(filePath)) { if (ClsidPathDic.ContainsKey(guid)) { ClsidPathDic[guid] = guidKey.Name; } else { ClsidPathDic.Add(guid, guidKey.Name); } break; } } } } FilePathDic.Add(guid, filePath); } return(filePath); }