🐛 修复了某些路径无法建立相对路径导致程序启动崩溃的bug
This commit is contained in:
@@ -159,16 +159,23 @@ namespace GeekDesk.Util
|
||||
|
||||
public static string MakeRelativePath(string fromPath, string toPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(toPath) || string.IsNullOrEmpty(fromPath)) return null;
|
||||
Uri file = new Uri(@toPath);
|
||||
// Must end in a slash to indicate folder
|
||||
Uri folder = new Uri(@fromPath);
|
||||
string relativePath =
|
||||
Uri.UnescapeDataString(
|
||||
folder.MakeRelativeUri(file)
|
||||
.ToString()
|
||||
.Replace('/', Path.DirectorySeparatorChar)
|
||||
);
|
||||
string relativePath = null;
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(toPath) || string.IsNullOrEmpty(fromPath)) return null;
|
||||
Uri file = new Uri(@toPath);
|
||||
// Must end in a slash to indicate folder
|
||||
Uri folder = new Uri(@fromPath);
|
||||
relativePath =
|
||||
Uri.UnescapeDataString(
|
||||
folder.MakeRelativeUri(file)
|
||||
.ToString()
|
||||
.Replace('/', Path.DirectorySeparatorChar)
|
||||
);
|
||||
} catch (Exception ex)
|
||||
{
|
||||
LogUtil.WriteErrorLog(ex, "建立相对路径出错:fromPath:" + fromPath + ",toPath:" + toPath);
|
||||
}
|
||||
return relativePath;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user