Skip to content

Commit 89e2ffe

Browse files
author
ComputerElite
committed
Revert "Add obb backup"
This reverts commit a9ccec2.
1 parent a9ccec2 commit 89e2ffe

11 files changed

Lines changed: 979 additions & 2656 deletions

AndroidTools.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using Android;
2+
using Android.App;
3+
using Android.Content;
4+
using Android.Content.PM;
5+
using System;
6+
using System.Collections.Generic;
7+
using Xamarin.Essentials;
8+
using static Xamarin.Essentials.Permissions;
9+
10+
namespace QuestAppVersionSwitcher.Core
11+
{
12+
public class AndroidService
13+
{
14+
public static List<App> GetInstalledApps()
15+
{
16+
List<App> inApps = new List<App>();
17+
IList<ApplicationInfo> apps = Android.App.Application.Context.PackageManager.GetInstalledApplications(PackageInfoFlags.MatchAll);
18+
for (int i = 0; i < apps.Count; i++)
19+
{
20+
inApps.Add(new App(apps[i].LoadLabel(Android.App.Application.Context.PackageManager), apps[i].PackageName));
21+
}
22+
return inApps;
23+
}
24+
25+
public static string FindAPKLocation(string package)
26+
{
27+
try
28+
{
29+
ApplicationInfo applicationInfo = Android.App.Application.Context.PackageManager.GetApplicationInfo(package, PackageInfoFlags.MatchAll);
30+
return (applicationInfo != null) ? applicationInfo.SourceDir : null;
31+
}
32+
catch (PackageManager.NameNotFoundException)
33+
{
34+
}
35+
return null;
36+
}
37+
38+
public static void InitiateUninstallPackage(string package)
39+
{
40+
Intent uninstallIntent = new Intent(Intent.ActionDelete, Android.Net.Uri.Parse("package:" + package));
41+
//uninstallIntent.AddFlags(ActivityFlags.NewTask);
42+
CoreService.context.StartActivity(uninstallIntent);
43+
}
44+
45+
public static bool IsPackageInstalled(string package)
46+
{
47+
bool installed = false;
48+
foreach(App a in GetInstalledApps())
49+
{
50+
if (a.PackageName == package) { installed = true; break; }
51+
}
52+
return installed;
53+
}
54+
55+
public static void InitiateInstallApk(string apkLocation)
56+
{
57+
Intent intent = new Intent(Intent.ActionView);
58+
intent.SetDataAndType(FileProvider.GetUriForFile(CoreService.context, CoreService.context.PackageName + ".provider", new Java.IO.File(apkLocation)), "application/vnd.android.package-archive");
59+
//intent.SetFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask);
60+
intent.SetFlags(ActivityFlags.GrantReadUriPermission);
61+
CoreService.context.StartActivity(intent);
62+
}
63+
}
64+
65+
public class App
66+
{
67+
public string AppName { get; set; }
68+
public string PackageName { get; set; }
69+
70+
public App(string appName, string packageName)
71+
{
72+
AppName = appName;
73+
PackageName = packageName;
74+
}
75+
}
76+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
using ComputerUtils.Logging;
2+
using System;
3+
using System.IO;
4+
5+
namespace ComputerUtils.FileManaging
6+
{
7+
public class FileManager
8+
{
9+
public static long GetDirSize(string dir)
10+
{
11+
return GetDirSize(new DirectoryInfo(dir));
12+
}
13+
14+
public static long GetDirSize(DirectoryInfo d)
15+
{
16+
long size = 0;
17+
FileInfo[] fis = d.GetFiles();
18+
foreach (FileInfo fi in fis)
19+
{
20+
size += fi.Length;
21+
}
22+
DirectoryInfo[] dis = d.GetDirectories();
23+
foreach (DirectoryInfo di in dis)
24+
{
25+
size += GetDirSize(di);
26+
}
27+
return size;
28+
}
29+
30+
public static string GetParentDirIfExisting(string dir)
31+
{
32+
try
33+
{
34+
DirectoryInfo i = Directory.GetParent(dir);
35+
if (i == null) return dir;
36+
return i.FullName;
37+
}
38+
catch
39+
{
40+
return dir;
41+
}
42+
}
43+
public static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs, bool output = true)
44+
{
45+
// Get the subdirectories for the specified directory.
46+
try
47+
{
48+
if (Directory.Exists(destDirName)) Directory.Delete(destDirName, true);
49+
}
50+
catch { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Couldn't delete " + destDirName); Console.ForegroundColor = ConsoleColor.White; }
51+
52+
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
53+
54+
if (!dir.Exists)
55+
{
56+
throw new DirectoryNotFoundException(
57+
"Source directory does not exist or could not be found: "
58+
+ sourceDirName);
59+
}
60+
61+
DirectoryInfo[] dirs = dir.GetDirectories();
62+
63+
// If the destination directory doesn't exist, create it.
64+
Directory.CreateDirectory(destDirName);
65+
66+
// Get the files in the directory and copy them to the new location.
67+
FileInfo[] files = dir.GetFiles();
68+
foreach (FileInfo file in files)
69+
{
70+
try
71+
{
72+
if (output) Console.WriteLine("Copying " + file.Name);
73+
Logger.Log("Copying " + file.Name);
74+
string tempPath = System.IO.Path.Combine(destDirName, file.Name);
75+
file.CopyTo(tempPath, true);
76+
}
77+
catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR copying " + file.Name); Console.ForegroundColor = ConsoleColor.White; Logger.Log("Error copying " + file.Name + ": " + e.ToString(), LoggingType.Error); }
78+
}
79+
80+
// If copying subdirectories, copy them and their contents to new location.
81+
if (copySubDirs)
82+
{
83+
foreach (DirectoryInfo subdir in dirs)
84+
{
85+
string tempPath = System.IO.Path.Combine(destDirName, subdir.Name);
86+
DirectoryCopy(subdir.FullName, tempPath, copySubDirs);
87+
}
88+
}
89+
}
90+
91+
public static DirectoryInfo CreateDirectoryIfNotExisting(string path)
92+
{
93+
if (!Directory.Exists(path))
94+
{
95+
Logger.Log("Creating " + path);
96+
Directory.CreateDirectory(path);
97+
}
98+
return new DirectoryInfo(path);
99+
}
100+
101+
public static DirectoryInfo RecreateDirectoryIfExisting(string path)
102+
{
103+
104+
if (Directory.Exists(path))
105+
{
106+
Logger.Log("Deleting " + path);
107+
SetAttributesNormal(new DirectoryInfo(path));
108+
Directory.Delete(path, true);
109+
}
110+
Logger.Log("Creating " + path);
111+
Directory.CreateDirectory(path);
112+
return new DirectoryInfo(path);
113+
}
114+
115+
public static void SetAttributesNormal(DirectoryInfo dir)
116+
{
117+
foreach (DirectoryInfo subDir in dir.GetDirectories()) SetAttributesNormal(subDir);
118+
foreach (FileInfo file in dir.GetFiles()) file.Attributes = FileAttributes.Normal;
119+
}
120+
}
121+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using ComputerUtils.RegexStuff;
2+
using System;
3+
using System.IO;
4+
using System.Text.RegularExpressions;
5+
6+
namespace ComputerUtils.Logging {
7+
public class Logger
8+
{
9+
public static string logFile { get; set; } = "";
10+
public static bool removeUsernamesFromLog { get; set; } = true;
11+
public static bool displayLogInConsole { get; set; } = false;
12+
public static bool longLogInConsole { get; set; } = true;
13+
14+
public static void Log(string text, LoggingType loggingType = LoggingType.Info)
15+
{
16+
//Remove username
17+
if (removeUsernamesFromLog) text = RegexTemplates.RemoveUserName(text);
18+
string linePrefix = GetLinePrefix(loggingType);
19+
text = linePrefix + text.Replace("\n", "\n" + linePrefix);
20+
if (displayLogInConsole)
21+
{
22+
switch (loggingType)
23+
{
24+
case LoggingType.Error:
25+
Console.ForegroundColor = ConsoleColor.Red;
26+
break;
27+
case LoggingType.Info:
28+
Console.ForegroundColor = ConsoleColor.White;
29+
break;
30+
case LoggingType.Crash:
31+
Console.ForegroundColor = ConsoleColor.Red;
32+
break;
33+
case LoggingType.Warning:
34+
Console.ForegroundColor = ConsoleColor.Yellow;
35+
break;
36+
case LoggingType.Debug:
37+
Console.ForegroundColor = ConsoleColor.DarkYellow;
38+
break;
39+
}
40+
Console.WriteLine(longLogInConsole ? text : text.Replace(linePrefix, ""));
41+
Console.ForegroundColor = ConsoleColor.White;
42+
}
43+
if (logFile == "") return;
44+
File.AppendAllText(logFile, "\n" + text);
45+
}
46+
public static void LogRaw(string text)
47+
{
48+
if (logFile == "") return;
49+
File.AppendAllText(logFile, text);
50+
}
51+
52+
public static string GetLinePrefix(LoggingType loggingType)
53+
{
54+
DateTime t = DateTime.Now;
55+
return "[" + t.Day.ToString("d2") + "." + t.Month.ToString("d2") + "." + t.Year.ToString("d4") + " " + t.Hour.ToString("d2") + ":" + t.Minute.ToString("d2") + ":" + t.Second.ToString("d2") + "." + t.Millisecond.ToString("d5") + "] " + (Enum.GetName(typeof(LoggingType), loggingType) + ":").PadRight(10);
56+
}
57+
58+
public static void SetLogFile(string file)
59+
{
60+
logFile = file;
61+
}
62+
}
63+
64+
public enum LoggingType
65+
{
66+
Info = 0,
67+
Warning = 1,
68+
Error = 2,
69+
Debug = 3,
70+
Crash = 4
71+
}
72+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Text.RegularExpressions;
3+
4+
namespace ComputerUtils.RegexStuff
5+
{
6+
public class RegexTemplates
7+
{
8+
public static String SystemDirFolderRegex = @"[A-Z]:\\(Program Files( x86)?|Windows)";
9+
public static bool IsIP(String input)
10+
{
11+
return System.Text.RegularExpressions.Regex.IsMatch(input, "((2(5[0-5]|[0-4][0-9])|1?[0-9]?[0-9])\\.){3}(2(5[0-5]|[0-4][0-9])|1?[0-9]?[0-9])");
12+
}
13+
14+
public static String GetIP(String input)
15+
{
16+
Match found = Regex.Match(input, "((2(5[0-5]|[0-4][0-9])|1?[0-9]?[0-9])\\.){3}(2(5[0-5]|[0-4][0-9])|1?[0-9]?[0-9])");
17+
if (!found.Success) return "";
18+
return found.Value;
19+
}
20+
21+
public static bool IsDiscordInvite(String input)
22+
{
23+
return Regex.IsMatch(input, "(https?://)?(www.)?(discord.(gg|io|me|li)|discordapp.com/invite)/.+[a-zA-Z0-9]");
24+
}
25+
26+
public static String GetDiscordInvite(String input)
27+
{
28+
Match found = Regex.Match(input, "(https ?://)?(www.)?(discord.(gg|io|me|li)|discordapp.com/invite)/.+[a-zA-Z0-9]");
29+
if (!found.Success) return "";
30+
return found.Value;
31+
}
32+
33+
public static bool IsInSystemFolder(String input)
34+
{
35+
return Regex.IsMatch(input, SystemDirFolderRegex);
36+
}
37+
38+
public static String RemoveUserName(String input)
39+
{
40+
return Regex.Replace(input, @"([A-Z]{1}\:\\[Uu]sers\\)([^\\]*\\)(.*)", "$1$3");
41+
}
42+
43+
}
44+
}

0 commit comments

Comments
 (0)