diff --git a/APKToolGUI/ApkTool/AaptParser.cs b/APKToolGUI/ApkTool/AaptParser.cs index eb286af..786e27b 100644 --- a/APKToolGUI/ApkTool/AaptParser.cs +++ b/APKToolGUI/ApkTool/AaptParser.cs @@ -108,26 +108,26 @@ namespace APKToolGUI.Utils switch (line.Split(':')[0]) { case "package": - PackageName = StringExt.Regex(@"(?<=package: name=\')(.*?)(?=\')", line); - VersionName = StringExt.Regex(@"(?<=versionName=\')(.*?)(?=\')", line); - VersionCode = StringExt.Regex(@"(?<=versionCode=\')(.*?)(?=\')", line); + PackageName = StringExt.RegexExtract(@"(?<=package: name=\')(.*?)(?=\')", line); + VersionName = StringExt.RegexExtract(@"(?<=versionName=\')(.*?)(?=\')", line); + VersionCode = StringExt.RegexExtract(@"(?<=versionCode=\')(.*?)(?=\')", line); break; case "uses-permission": - permissionsBuilder.AppendLine(StringExt.Regex(@"(?<=name=\')(.*?)(?=\')", line)); + permissionsBuilder.AppendLine(StringExt.RegexExtract(@"(?<=name=\')(.*?)(?=\')", line)); break; case "sdkVersion": - MinSdkVersionDetailed = SdkToAndroidVer(StringExt.Regex(@"(?<=sdkVersion:\')(.*?)(?=\')", line)); - MinSdkVersion = StringExt.Regex(@"(?<=sdkVersion:\')(.*?)(?=\')", line); + MinSdkVersionDetailed = SdkToAndroidVer(StringExt.RegexExtract(@"(?<=sdkVersion:\')(.*?)(?=\')", line)); + MinSdkVersion = StringExt.RegexExtract(@"(?<=sdkVersion:\')(.*?)(?=\')", line); break; case "targetSdkVersion": - TargetSdkVersionDetailed = SdkToAndroidVer(StringExt.Regex(@"(?<=targetSdkVersion:\')(.*?)(?=\')", line)); - TargetSdkVersion = StringExt.Regex(@"(?<=targetSdkVersion:\')(.*?)(?=\')", line); + TargetSdkVersionDetailed = SdkToAndroidVer(StringExt.RegexExtract(@"(?<=targetSdkVersion:\')(.*?)(?=\')", line)); + TargetSdkVersion = StringExt.RegexExtract(@"(?<=targetSdkVersion:\')(.*?)(?=\')", line); break; case "application-label": - AppName = StringExt.Regex(@"(?<=application-label:\')(.*?)(?=\')", line); + AppName = StringExt.RegexExtract(@"(?<=application-label:\')(.*?)(?=\')", line); break; case "launchable-activity": - LaunchableActivity = StringExt.Regex(@"(?<=name=\')(.*?)(?=\')", line); + LaunchableActivity = StringExt.RegexExtract(@"(?<=name=\')(.*?)(?=\')", line); break; case "supports-screens": var screens = Regex.Matches(line.Split(':')[1], @"(?<= \')(.*?)(?=\')").Cast().Select(m => m.Value).ToList(); @@ -161,13 +161,13 @@ namespace APKToolGUI.Utils ApkMirrorLink = "https://www.apkmirror.com/?post_type=app_release&searchtype=apk&s=" + PackageName; ApkGkLink = "https://apkgk.com/" + PackageName + "/download"; - AppIcon120 = StringExt.Regex(@"(?<=application-icon-120:\')(.*?)(?=\')", FullInfo); - AppIcon160 = StringExt.Regex(@"(?<=application-icon-160:\')(.*?)(?=\')", FullInfo); - AppIcon240 = StringExt.Regex(@"(?<=application-icon-240:\')(.*?)(?=\')", FullInfo); - AppIcon320 = StringExt.Regex(@"(?<=application-icon-320:\')(.*?)(?=\')", FullInfo); - AppIcon480 = StringExt.Regex(@"(?<=application-icon-480:\')(.*?)(?=\')", FullInfo); - AppIcon640 = StringExt.Regex(@"(?<=application-icon-640:\')(.*?)(?=\')", FullInfo); - AppIcon65534 = StringExt.Regex(@"(?<=application-icon-65534:\')(.*?)(?=\')", FullInfo); + AppIcon120 = StringExt.RegexExtract(@"(?<=application-icon-120:\')(.*?)(?=\')", FullInfo); + AppIcon160 = StringExt.RegexExtract(@"(?<=application-icon-160:\')(.*?)(?=\')", FullInfo); + AppIcon240 = StringExt.RegexExtract(@"(?<=application-icon-240:\')(.*?)(?=\')", FullInfo); + AppIcon320 = StringExt.RegexExtract(@"(?<=application-icon-320:\')(.*?)(?=\')", FullInfo); + AppIcon480 = StringExt.RegexExtract(@"(?<=application-icon-480:\')(.*?)(?=\')", FullInfo); + AppIcon640 = StringExt.RegexExtract(@"(?<=application-icon-640:\')(.*?)(?=\')", FullInfo); + AppIcon65534 = StringExt.RegexExtract(@"(?<=application-icon-65534:\')(.*?)(?=\')", FullInfo); result = true; } @@ -256,7 +256,7 @@ namespace APKToolGUI.Utils //File.WriteAllText("R:\\t.txt", ps); string icondl = Path.Combine(cacheDir, "icon.png"); Directory.CreateDirectory(cacheDir); - w.DownloadFile(StringExt.Regex(@"(?<=\""image\"":\"")(.*?)(?=\"",\"")", ps), icondl); + w.DownloadFile(StringExt.RegexExtract(@"(?<=\""image\"":\"")(.*?)(?=\"",\"")", ps), icondl); iconLocation = icondl; } catch (System.Net.WebException ex) diff --git a/APKToolGUI/Forms/FormMain.cs b/APKToolGUI/Forms/FormMain.cs index 964880f..c445afd 100644 --- a/APKToolGUI/Forms/FormMain.cs +++ b/APKToolGUI/Forms/FormMain.cs @@ -59,6 +59,8 @@ namespace APKToolGUI Text += " - v" + ProductVersion; Application.ApplicationExit += new EventHandler(Application_ApplicationExit); + aapt = new AaptParser(); + if (!File.Exists(Settings.Default.Decode_InputAppPath)) Settings.Default.Decode_InputAppPath = ""; if (!Directory.Exists(Settings.Default.Build_InputDir)) @@ -203,7 +205,7 @@ namespace APKToolGUI ToLog(ApktoolEventType.Success, Language.Done); ToStatus(Language.Done, Resources.done); } - catch (Exception) + catch (Exception ex) { #if DEBUG ToLog(ApktoolEventType.Warning, Language.ErrorGettingApkInfo + "\n" + ex.ToString()); @@ -419,6 +421,7 @@ namespace APKToolGUI color = Color.DarkOrange; else color = Color.Orange; + color = Color.White; break; case ApktoolEventType.Unknown: if (Program.IsDarkTheme()) diff --git a/APKToolGUI/Forms/FormSettings.cs b/APKToolGUI/Forms/FormSettings.cs index b5b494a..9aeaff4 100644 --- a/APKToolGUI/Forms/FormSettings.cs +++ b/APKToolGUI/Forms/FormSettings.cs @@ -139,7 +139,7 @@ namespace APKToolGUI if (Language.SystemLanguage.Equals(comboBox1.SelectedItem.ToString())) Settings.Default.Culture = "Auto"; else - Settings.Default.Culture = StringExt.Regex(@"(?<=\[)(.*?)(?=\])", comboBox1.SelectedItem.ToString()); + Settings.Default.Culture = StringExt.RegexExtract(@"(?<=\[)(.*?)(?=\])", comboBox1.SelectedItem.ToString()); Settings.Default.Theme = themeComboBox.SelectedIndex; Settings.Default.Save(); diff --git a/APKToolGUI/Program.cs b/APKToolGUI/Program.cs index 178820a..e0c2023 100644 --- a/APKToolGUI/Program.cs +++ b/APKToolGUI/Program.cs @@ -10,6 +10,7 @@ using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.InteropServices; +using System.Text; using System.Windows.Forms; namespace APKToolGUI @@ -165,12 +166,13 @@ namespace APKToolGUI List missigFiles = MissingFilesCheck(); if (missigFiles.Count > 0) { - String files = Environment.NewLine; + StringBuilder filesBuilder = new StringBuilder(); + filesBuilder.AppendLine(); foreach (String file in missigFiles) { - files += file + Environment.NewLine; + filesBuilder.AppendLine(file); } - MessageBox.Show(Language.RequiredFilesMissing + files, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(Language.RequiredFilesMissing + filesBuilder.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); //Application.Exit(); return false; } diff --git a/APKToolGUI/Utils/CommonUtils.cs b/APKToolGUI/Utils/CommonUtils.cs index d1904d2..fb18eab 100644 --- a/APKToolGUI/Utils/CommonUtils.cs +++ b/APKToolGUI/Utils/CommonUtils.cs @@ -17,7 +17,7 @@ namespace APKToolGUI.Utils { if (mf.Contains(" + /// Extracts a string from the input using the provided regex pattern. + /// + /// The regex pattern to match. + /// The input string to search. + /// The matched string or empty string if no match found. + public static string RegexExtract(string pattern, string input) + { + Regex regex = new Regex(pattern); + Match matched = regex.Match(input); return matched.ToString(); } @@ -24,14 +42,14 @@ namespace APKToolGUI.Utils { const string chars = "abcdefghijklmnopqrstuvwxyz"; return new string(Enumerable.Repeat(chars, length) - .Select(s => s[random.Next(s.Length)]).ToArray()); + .Select(s => s[ThreadRandom.Next(s.Length)]).ToArray()); } public static string RandStrWithCaps(int length) { const string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; return new string(Enumerable.Repeat(chars, length) - .Select(s => s[random.Next(s.Length)]).ToArray()); + .Select(s => s[ThreadRandom.Next(s.Length)]).ToArray()); } ///