From 327f0340901488767f403c558f338d4630711d6c Mon Sep 17 00:00:00 2001 From: Harimurti Date: Mon, 18 Jan 2021 20:13:48 +0700 Subject: [PATCH] lib: add GetShortPathName() fix : [aapt] asset path is neither a directory nor file (type=1) --- ApkManager/Lib/Aapt.cs | 2 +- ApkManager/Lib/Adb.cs | 2 +- ApkManager/Lib/LibExtended.cs | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ApkManager/Lib/Aapt.cs b/ApkManager/Lib/Aapt.cs index 6b7f4a5..8916a3c 100644 --- a/ApkManager/Lib/Aapt.cs +++ b/ApkManager/Lib/Aapt.cs @@ -95,7 +95,7 @@ public static async Task DumbBadging(string pathApk) try { - output = await RunAsync("dump badging \"{0}\"", pathApk); + output = await RunAsync("dump badging \"{0}\"", pathApk.GetShortPathName()); } catch (Exception e) { diff --git a/ApkManager/Lib/Adb.cs b/ApkManager/Lib/Adb.cs index dfaf967..bc27d8a 100644 --- a/ApkManager/Lib/Adb.cs +++ b/ApkManager/Lib/Adb.cs @@ -182,7 +182,7 @@ public async Task 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) diff --git a/ApkManager/Lib/LibExtended.cs b/ApkManager/Lib/LibExtended.cs index c99d905..e75a832 100644 --- a/ApkManager/Lib/LibExtended.cs +++ b/ApkManager/Lib/LibExtended.cs @@ -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 @@ -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(); + } } }