Files

57 lines
1.8 KiB
C#
Raw Permalink Normal View History

2024-06-23 10:54:02 +02:00
using System;
using System.Linq;
namespace AndroidDebugBridge
{
public partial class AndroidDebugBridgeTransport
{
public (string variableName, string variableValue)[]? GetAllVariables()
{
if (!IsConnected)
{
throw new Exception("Cannot get all variables with no accepted connection!");
}
2024-06-23 10:54:02 +02:00
(string variableName, string variableValue)[]? result = null;
try
{
string getPropAnswer = Shell("getprop");
return getPropAnswer.Split("\n")
.Where(t =>
t.Contains(':') &&
t.Contains('[') &&
t.Contains(']') &&
t.Contains("]: ["))
.Select(t =>
{
string[] cleanedUpPart = t.Trim()[1..^1].Split("]: [");
return (cleanedUpPart[0], string.Join("]: [", cleanedUpPart.Skip(1)));
})
.ToArray();
}
catch (Exception) { }
return result;
}
public string? GetVariableValue(string variableName)
{
if (!IsConnected)
{
throw new Exception("Cannot get a specific variable with no accepted connection!");
}
2024-06-23 10:54:02 +02:00
string? result = null;
try
{
2024-06-23 15:59:21 +02:00
result = Shell($"getprop {variableName}").TrimEnd('\u0003').TrimEnd('\n').TrimEnd('\r');
2024-06-23 10:54:02 +02:00
}
catch (Exception) { }
return result;
}
}
}