Skip to content

Commit

Permalink
- Removed a lot of obsolete code
Browse files Browse the repository at this point in the history
- Better thread control
- Slimmed down a lot of classes
- More efficient processing
- Better control of ADB process
- Reliable clean up on exit
- Some GUI fixes
- Minor code changes
  • Loading branch information
hexadezi committed Jan 9, 2021
1 parent 24d32bd commit 913ee2c
Show file tree
Hide file tree
Showing 43 changed files with 3,655 additions and 4,196 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# CS0414: Dem Feld "MainForm.RICHTEXTBOX_REFRSH_INTERVAL" wurde ein Wert zugewiesen, der aber nie verwendet wird.
dotnet_diagnostic.CS0414.severity = warning
12 changes: 10 additions & 2 deletions adbGUI.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.30804.86
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "adbGUI", "adbGUI\adbGUI.csproj", "{ECE8C416-960E-4F2F-9B1D-AB260B668D96}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F4917431-D344-4675-A094-FC1DE011D666}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -26,4 +31,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {32CC4BA1-0725-4202-80A1-E18F824E258D}
EndGlobalSection
EndGlobal
403 changes: 194 additions & 209 deletions adbGUI/Forms/BackupRestore.Designer.cs

Large diffs are not rendered by default.

246 changes: 120 additions & 126 deletions adbGUI/Forms/BackupRestore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,130 +3,124 @@

namespace adbGUI.Forms
{
using System;
using System.Globalization;
using System.Windows.Forms;
using Methods;

public partial class BackupRestore : Form
{
// todo backup restore testen

private readonly CmdProcess _adb;
private readonly FormMethods _formMethods;

public BackupRestore(CmdProcess adbFrm, FormMethods formMethodsFrm)
{
InitializeComponent();

_adb = adbFrm;
_formMethods = formMethodsFrm;
}

private void Btn_BackupBrowse_Click(object sender, EventArgs e)
{
saveFileDialog.FileName = "backup_" + DateTime.Now.ToString(CultureInfo.InvariantCulture).Replace(' ', '_')
.Replace(':', '.');
saveFileDialog.Filter = @" .ab|*.ab";

if (saveFileDialog.ShowDialog() == DialogResult.OK) txt_BackupPathTo.Text = saveFileDialog.FileName;
}

private void Btn_BackupStart_Click(object sender, EventArgs e)
{
var name = " -f \"" + txt_BackupPathTo.Text + "\"";
var apk = " -noapk";
var shared = " -noshared";
const string all = " -all";
var system = " -system";


if (cbo_BackupPackage.Checked == false)
{
if (txt_BackupPathTo.Text == "")
{
MessageBox.Show(@"Please select a destination!", @"Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
else
{
if (cbo_BackupWithApk.Checked) apk = " -apk";
if (cbo_BackupShared.Checked) shared = " -shared";
if (cbo_BackupNoSystem.Checked) system = " -nosystem";

_adb.StartProcessing("adb backup" + apk + shared + all + system + name,
_formMethods.SelectedDevice());
}
}
else
{
var package = cbx_BackupPackage.SelectedItem.ToString();

if (txt_BackupPathTo.Text == "")
MessageBox.Show(@"Please select a destination!", @"Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
else
_adb.StartProcessing("adb backup -apk " + package + name, _formMethods.SelectedDevice());
}
}

private void Cbo_BackupPackage_CheckedChanged(object sender, EventArgs e)
{
if (cbo_BackupPackage.Checked)
{
cbo_BackupNoSystem.Enabled = false;
cbo_BackupNoSystem.Checked = false;
cbo_BackupShared.Enabled = false;
cbo_BackupShared.Checked = false;
cbo_BackupWithApk.Enabled = false;
cbo_BackupWithApk.Checked = false;
cbx_BackupPackage.Visible = true;
label8.Visible = true;

groupBox8.Enabled = false;
groupBox14.Enabled = false;

var output =
CmdProcess.StartProcessingInThread("adb shell pm list packages -3", _formMethods.SelectedDevice());

if (!string.IsNullOrEmpty(output))
{
foreach (var item in output.Split(new[] {"\n"}, StringSplitOptions.RemoveEmptyEntries))
cbx_BackupPackage.Items.Add(item.Remove(0, 8));

cbx_BackupPackage.Sorted = true;

if (cbx_BackupPackage.Items.Count > 0) cbx_BackupPackage.SelectedIndex = 0;
}

groupBox8.Enabled = true;
groupBox14.Enabled = true;
}
else
{
cbo_BackupNoSystem.Enabled = true;
cbo_BackupShared.Enabled = true;
cbo_BackupWithApk.Enabled = true;
cbx_BackupPackage.Visible = false;
cbx_BackupPackage.Items.Clear();
label8.Visible = false;
}
}

private void Btn_RestoreStart_Click(object sender, EventArgs e)
{
if (txt_RestorePath.Text == "")
MessageBox.Show(@"Please select a file!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
_adb.StartProcessing("adb restore \"" + txt_RestorePath.Text + "\"", _formMethods.SelectedDevice());
}

private void Btn_RestoreBrowse_Click(object sender, EventArgs e)
{
openFileDialog.FileName = "";
openFileDialog.Filter = @" .ab|*.ab";

if (openFileDialog.ShowDialog() == DialogResult.OK) txt_RestorePath.Text = openFileDialog.FileName;
}
}
using System;
using System.Globalization;
using System.Windows.Forms;
using Methods;

public partial class BackupRestore : ExtForm
{
// todo backup restore testen

public BackupRestore()
{
InitializeComponent();
}

private void Btn_BackupBrowse_Click(object sender, EventArgs e)
{
saveFileDialog.FileName = "backup_" + DateTime.Now.ToString(@"ddMMyyyy_HHmmss");
saveFileDialog.Filter = @" .ab|*.ab";

if (saveFileDialog.ShowDialog() == DialogResult.OK) txt_BackupPathTo.Text = saveFileDialog.FileName;
}

private void Btn_BackupStart_Click(object sender, EventArgs e)
{
var name = " -f \"" + txt_BackupPathTo.Text + "\"";
var apk = " -noapk";
var shared = " -noshared";
const string all = " -all";
var system = " -system";


if (cbo_BackupPackage.Checked)
{
if (cbx_BackupPackage.SelectedItem != null)
{
string package = cbx_BackupPackage.SelectedItem.ToString();

if (txt_BackupPathTo.Text == "")
MessageBox.Show(@"Please select a destination!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
HelperClass.Execute("adb backup -apk " + package + name);
}
}
else
{

if (txt_BackupPathTo.Text == "")
{
MessageBox.Show(@"Please select a destination!", @"Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
else
{
if (cbo_BackupWithApk.Checked) apk = " -apk";
if (cbo_BackupShared.Checked) shared = " -shared";
if (cbo_BackupNoSystem.Checked) system = " -nosystem";

HelperClass.Execute("adb backup" + apk + shared + all + system + name);
}
}
}

private void Cbo_BackupPackage_CheckedChanged(object sender, EventArgs e)
{
if (cbo_BackupPackage.Checked)
{
cbo_BackupNoSystem.Enabled = false;
cbo_BackupNoSystem.Checked = false;
cbo_BackupShared.Enabled = false;
cbo_BackupShared.Checked = false;
cbo_BackupWithApk.Enabled = false;
cbo_BackupWithApk.Checked = false;
cbx_BackupPackage.Visible = true;
label8.Visible = true;

groupBox8.Enabled = false;
groupBox14.Enabled = false;

var output = HelperClass.ExecuteWithOutput("adb shell pm list packages -3");

if (!string.IsNullOrEmpty(output))
{
foreach (var item in output.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries))
cbx_BackupPackage.Items.Add(item.Remove(0, 8));

cbx_BackupPackage.Sorted = true;

if (cbx_BackupPackage.Items.Count > 0) cbx_BackupPackage.SelectedIndex = 0;
}

groupBox8.Enabled = true;
groupBox14.Enabled = true;
}
else
{
cbo_BackupNoSystem.Enabled = true;
cbo_BackupShared.Enabled = true;
cbo_BackupWithApk.Enabled = true;
cbx_BackupPackage.Visible = false;
cbx_BackupPackage.Items.Clear();
label8.Visible = false;
}
}

private void Btn_RestoreStart_Click(object sender, EventArgs e)
{
if (txt_RestorePath.Text == "")
MessageBox.Show(@"Please select a file!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
HelperClass.Execute("adb restore \"" + txt_RestorePath.Text + "\"");
}

private void Btn_RestoreBrowse_Click(object sender, EventArgs e)
{
openFileDialog.FileName = "";
openFileDialog.Filter = @" .ab|*.ab";

if (openFileDialog.ShowDialog() == DialogResult.OK) txt_RestorePath.Text = openFileDialog.FileName;
}
}
}
5 changes: 3 additions & 2 deletions adbGUI/Forms/Credits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

namespace adbGUI.Forms
{
using System;
using adbGUI.Methods;
using System;
using System.Windows.Forms;

public partial class Credits : Form
public partial class Credits : ExtForm
{
public Credits()
{
Expand Down
15 changes: 5 additions & 10 deletions adbGUI/Forms/Density.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ namespace adbGUI.Forms
using System.Windows.Forms;
using Methods;

public partial class Density : Form
public partial class Density : ExtForm
{
private readonly CmdProcess _adb;
private readonly FormMethods _formMethods;

public Density(CmdProcess adbFrm, FormMethods formMethodsFrm)
public Density()
{
InitializeComponent();
_adb = adbFrm;
_formMethods = formMethodsFrm;
}

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
Expand All @@ -28,17 +23,17 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData)

private void Btn_showDpi_Click(object sender, EventArgs e)
{
_adb.StartProcessing("adb shell wm density", _formMethods.SelectedDevice());
HelperClass.Execute("adb shell wm density");
}

private void Btn_setDpi_Click(object sender, EventArgs e)
{
_adb.StartProcessing("adb shell wm density " + txt_phoneDpi.Text, _formMethods.SelectedDevice());
HelperClass.Execute("adb shell wm density " + txt_phoneDpi.Text);
}

private void Btn_resetDpi_Click(object sender, EventArgs e)
{
_adb.StartProcessing("adb shell wm density reset", _formMethods.SelectedDevice());
HelperClass.Execute("adb shell wm density reset");
}

private void DpiChange_KeyDown(object sender, KeyEventArgs e)
Expand Down
Loading

0 comments on commit 913ee2c

Please sign in to comment.