Browse Source

Merge pull request #2936 from icsharpcode/christophwille/2933

Fix 2933
pull/2944/head
Christoph Wille 2 years ago committed by GitHub
parent
commit
f467213b59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs
  2. 41
      ICSharpCode.Decompiler/Documentation/XmlDocumentationProvider.cs

27
ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Runtime.CompilerServices;
@ -104,26 +105,37 @@ namespace ICSharpCode.Decompiler.Documentation @@ -104,26 +105,37 @@ namespace ICSharpCode.Decompiler.Documentation
return fileName;
}
static string LookupLocalizedXmlDoc(string fileName)
/// <summary>
/// Given the assembly file name, looks up the XML documentation file name.
/// Returns null if no XML documentation file is found.
/// </summary>
internal static string LookupLocalizedXmlDoc(string fileName)
{
if (string.IsNullOrEmpty(fileName))
return null;
string xmlFileName = Path.ChangeExtension(fileName, ".xml");
string currentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
string localizedXmlDocFile = GetLocalizedName(xmlFileName, currentCulture);
CultureInfo currentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
string localizedXmlDocFile = GetLocalizedName(xmlFileName, currentCulture.Name);
string localizedXmlDocFallbackFile = GetLocalizedName(xmlFileName, currentCulture.TwoLetterISOLanguageName);
Debug.WriteLine("Try find XMLDoc @" + localizedXmlDocFile);
if (File.Exists(localizedXmlDocFile))
{
return localizedXmlDocFile;
}
Debug.WriteLine("Try find XMLDoc @" + localizedXmlDocFallbackFile);
if (File.Exists(localizedXmlDocFallbackFile))
{
return localizedXmlDocFallbackFile;
}
Debug.WriteLine("Try find XMLDoc @" + xmlFileName);
if (File.Exists(xmlFileName))
{
return xmlFileName;
}
if (currentCulture != "en")
if (currentCulture.TwoLetterISOLanguageName != "en")
{
string englishXmlDocFile = GetLocalizedName(xmlFileName, "en");
Debug.WriteLine("Try find XMLDoc @" + englishXmlDocFile);
@ -135,12 +147,9 @@ namespace ICSharpCode.Decompiler.Documentation @@ -135,12 +147,9 @@ namespace ICSharpCode.Decompiler.Documentation
return null;
}
static string GetLocalizedName(string fileName, string language)
private static string GetLocalizedName(string fileName, string language)
{
string localizedXmlDocFile = Path.GetDirectoryName(fileName);
localizedXmlDocFile = Path.Combine(localizedXmlDocFile, language);
localizedXmlDocFile = Path.Combine(localizedXmlDocFile, Path.GetFileName(fileName));
return localizedXmlDocFile;
return Path.Combine(Path.GetDirectoryName(fileName), language, Path.GetFileName(fileName));
}
}
}

41
ICSharpCode.Decompiler/Documentation/XmlDocumentationProvider.cs

@ -185,7 +185,7 @@ namespace ICSharpCode.Decompiler.Documentation @@ -185,7 +185,7 @@ namespace ICSharpCode.Decompiler.Documentation
.Replace("%CORSYSDIR%", corSysDir);
if (!Path.IsPathRooted(fileName))
fileName = Path.Combine(Path.GetDirectoryName(xmlFileName), fileName);
return LookupLocalizedXmlDoc(fileName);
return XmlDocLoader.LookupLocalizedXmlDoc(fileName);
}
static string AppendDirectorySeparator(string dir)
@ -196,45 +196,6 @@ namespace ICSharpCode.Decompiler.Documentation @@ -196,45 +196,6 @@ namespace ICSharpCode.Decompiler.Documentation
return dir + Path.DirectorySeparatorChar;
}
/// <summary>
/// Given the assembly file name, looks up the XML documentation file name.
/// Returns null if no XML documentation file is found.
/// </summary>
public static string LookupLocalizedXmlDoc(string fileName)
{
string xmlFileName = Path.ChangeExtension(fileName, ".xml");
string currentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
string localizedXmlDocFile = GetLocalizedName(xmlFileName, currentCulture);
Debug.WriteLine("Try find XMLDoc @" + localizedXmlDocFile);
if (File.Exists(localizedXmlDocFile))
{
return localizedXmlDocFile;
}
Debug.WriteLine("Try find XMLDoc @" + xmlFileName);
if (File.Exists(xmlFileName))
{
return xmlFileName;
}
if (currentCulture != "en")
{
string englishXmlDocFile = GetLocalizedName(xmlFileName, "en");
Debug.WriteLine("Try find XMLDoc @" + englishXmlDocFile);
if (File.Exists(englishXmlDocFile))
{
return englishXmlDocFile;
}
}
return null;
}
static string GetLocalizedName(string fileName, string language)
{
string localizedXmlDocFile = Path.GetDirectoryName(fileName);
localizedXmlDocFile = Path.Combine(localizedXmlDocFile, language);
localizedXmlDocFile = Path.Combine(localizedXmlDocFile, Path.GetFileName(fileName));
return localizedXmlDocFile;
}
#endregion
#region Load / Create Index

Loading…
Cancel
Save