Skip to content

Commit

Permalink
lib: add GetShortPathName()
Browse files Browse the repository at this point in the history
fix : [aapt] asset path is neither a directory nor file (type=1)
  • Loading branch information
hariimurti committed Jan 18, 2021
1 parent 4537d87 commit 327f034
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ApkManager/Lib/Aapt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static async Task<Result> DumbBadging(string pathApk)

try
{
output = await RunAsync("dump badging \"{0}\"", pathApk);
output = await RunAsync("dump badging \"{0}\"", pathApk.GetShortPathName());
}
catch (Exception e)
{
Expand Down
2 changes: 1 addition & 1 deletion ApkManager/Lib/Adb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public async Task<bool> Install(string device, string pathApk)
{
try
{
var result = await RunAsync("-s {0} install -r \"{1}\"", device, pathApk);
var result = await RunAsync("-s {0} install -r \"{1}\"", device, pathApk.GetShortPathName());
return result.Contains("Success");
}
catch (Exception e)
Expand Down
16 changes: 16 additions & 0 deletions ApkManager/Lib/LibExtended.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;

namespace ApkManager.Lib
Expand Down Expand Up @@ -51,5 +53,19 @@ public static string TrimInvalidFileNameChars(this string text)

return text.Trim();
}

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern int GetShortPathName(
[MarshalAs(UnmanagedType.LPTStr)] string path,
[MarshalAs(UnmanagedType.LPTStr)] StringBuilder shortPath,
int shortPathLength
);

public static string GetShortPathName(this string path)
{
var shortPath = new StringBuilder(255);
var result = GetShortPathName(path, shortPath, shortPath.Capacity);
return (result == 0) ? path : shortPath.ToString();
}
}
}

0 comments on commit 327f034

Please sign in to comment.