Skip to content

Commit

Permalink
lib: aapt: improve regex
Browse files Browse the repository at this point in the history
  • Loading branch information
hariimurti committed Jun 6, 2020
1 parent 651dd30 commit 8325893
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions ApkManager/Lib/Aapt.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
Expand Down Expand Up @@ -88,7 +88,7 @@ public static async Task<string> RunAsync(string command, params object[] args)

public static async Task<Result> DumbBadging(string pathApk)
{
var output = string.Empty;
string output;

try
{
Expand All @@ -111,23 +111,23 @@ public static async Task<Result> DumbBadging(string pathApk)
if (match.Success) apk.PackageName = match.Groups[1].Value;

//versionCode
match = Regex.Match(output, "package.+versionCode='(.+?)'");
match = Regex.Match(output, "package.+ versionCode='(.+?)'");
if (match.Success)
{
double.TryParse(match.Groups[1].Value, out double versionCode);
apk.VersionCode = versionCode;
}

//versionName
match = Regex.Match(output, "package.+versionName='(.+?)'");
match = Regex.Match(output, "package.+ versionName='(.+?)'");
if (match.Success) apk.VersionName = match.Groups[1].Value;

//label
match = Regex.Match(output, "application.+label='(.+?)'");
match = Regex.Match(output, "application: label='(.+?)'");
if (match.Success) apk.Label = match.Groups[1].Value;

//icon
match = Regex.Match(output, "application.+icon='(.+?)'");
match = Regex.Match(output, "application.+ icon='(.+?)'");
if (match.Success) apk.Icon = GetIconFrom(pathApk, match.Groups[1].Value);

//sdkVersion
Expand All @@ -151,16 +151,16 @@ public static async Task<Result> DumbBadging(string pathApk)
foreach (Match m in matches) apk.Permissions.Add(m.Groups[1].Value);

//native-code
match = Regex.Match(output, "native-code: '(.+)'");
match = Regex.Match(output, "native-code: '([^:=]+)'");
if (match.Success)
{
apk.AbiList = match.Groups[1].Value.Replace("' '",", ");
apk.Platforms = match.Groups[1].Value.Replace("' '", " ").Split(' ').ToList();
apk.Platforms = match.Groups[1].Value.Replace("' '"," ").Split(' ').ToList();
}
else
{
apk.AbiList = "any";
apk.Platforms.Add("any");
apk.AbiList = "any-cpu";
apk.Platforms.Add("any-cpu");
}

//launchable-activity
Expand Down

0 comments on commit 8325893

Please sign in to comment.