-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2.新增了分享链接的支持
- Loading branch information
Showing
9 changed files
with
328 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace WechatPCMsgBakTool.Helpers | ||
{ | ||
public static class DevicePathMapper | ||
{ | ||
[DllImport("Kernel32.dll", CharSet = CharSet.Unicode)] | ||
private static extern uint QueryDosDevice([In] string lpDeviceName, [Out] StringBuilder lpTargetPath, [In] int ucchMax); | ||
|
||
public static string FromDevicePath(string devicePath) | ||
{ | ||
var drive = Array.Find(DriveInfo.GetDrives(), d => devicePath.StartsWith(d.GetDevicePath(), StringComparison.InvariantCultureIgnoreCase)); | ||
return drive != null ? | ||
devicePath.ReplaceFirst(drive.GetDevicePath(), drive.GetDriveLetter()) : | ||
null; | ||
} | ||
|
||
private static string GetDevicePath(this DriveInfo driveInfo) | ||
{ | ||
var devicePathBuilder = new StringBuilder(128); | ||
return QueryDosDevice(driveInfo.GetDriveLetter(), devicePathBuilder, devicePathBuilder.Capacity + 1) != 0 ? | ||
devicePathBuilder.ToString() : | ||
null; | ||
} | ||
|
||
private static string GetDriveLetter(this DriveInfo driveInfo) | ||
{ | ||
return driveInfo.Name.Substring(0, 2); | ||
} | ||
|
||
private static string ReplaceFirst(this string text, string search, string replace) | ||
{ | ||
int pos = text.IndexOf(search); | ||
if (pos < 0) | ||
{ | ||
return text; | ||
} | ||
return text.Substring(0, pos) + replace + text.Substring(pos + search.Length); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.