Skip to content
This repository has been archived by the owner on May 16, 2020. It is now read-only.

Commit

Permalink
menambahkan config
Browse files Browse the repository at this point in the history
  • Loading branch information
hariimurti committed Jul 26, 2017
1 parent 1192915 commit 0699337
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Apk_Installer/Apk_Installer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
<HintPath>..\packages\Costura.Fody.1.6.2\lib\dotnet\Costura.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -65,6 +68,7 @@
<ItemGroup>
<Compile Include="ApkFile.cs" />
<Compile Include="ComboboxItem.cs" />
<Compile Include="Config.cs" />
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
Expand Down
80 changes: 80 additions & 0 deletions Apk_Installer/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using Newtonsoft.Json;
using System.IO;

namespace Apk_Installer
{
class Config
{
class Data
{
public string ip_address { get; set; }
public int port { get; set; }
public bool register_apk { get; set; }
}

private static string CONFIG_FILE = "config.ini";
private Data json_config;
private static JsonSerializerSettings JSON_SETTINGS = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Include,
};

public Config()
{
string raw_config;

if (File.Exists(CONFIG_FILE))
{
raw_config = File.ReadAllText(CONFIG_FILE);
}
else
{
var data = new
{
ip_address = "192.168.1.101",
port = 5555,
register_apk = true
};
raw_config = JsonConvert.SerializeObject(data, JSON_SETTINGS);
File.WriteAllText(CONFIG_FILE, raw_config);
}

json_config = JsonConvert.DeserializeObject<Data>(raw_config);
}

public void Save()
{
string raw_config = JsonConvert.SerializeObject(json_config, JSON_SETTINGS);
File.WriteAllText(CONFIG_FILE, raw_config);
}

public bool getRegisterApk()
{
return json_config.register_apk;
}

public string getIPaddress()
{
return json_config.ip_address;
}

public int getPort()
{
return json_config.port;
}

public void setRegisterApk(bool value)
{
json_config.register_apk = value;
this.Save();
}

public void setAdbWifi(string newIpAddress, int newPort)
{
json_config.ip_address = newIpAddress;
json_config.port = newPort;
this.Save();
}
}
}
9 changes: 7 additions & 2 deletions Apk_Installer/FileAssociation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,19 @@ public static bool isRegistered()
return true;
}

public static void SetAssociation()
public static bool SetAssociation()
{
bool retval = true;
if (!isRegistered())
{
DialogResult askToSet = MessageBox.Show("Set this for default opening file apk?",
Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (askToSet == DialogResult.Yes) Register();
if (askToSet == DialogResult.Yes)
Register();
else
retval = false;
}
return retval;
}
}
}
14 changes: 13 additions & 1 deletion Apk_Installer/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@ namespace Apk_Installer
public partial class MainForm : Form
{
private static string LoadedApk = null;
private Config config;

public MainForm(string arg)
{
InitializeComponent();

this.Text = Application.ProductName + " v" + Application.ProductVersion.Substring(0, 3);
FileAssociation.SetAssociation();

config = new Config();
textIP.Text = config.getIPaddress();
textPort.Text = config.getPort().ToString();
if (config.getRegisterApk())
{
bool setAssoc = FileAssociation.SetAssociation();
if (config.getRegisterApk() != setAssoc)
config.setRegisterApk(setAssoc);
}

groupBox1.AllowDrop = true;
pictureBox1.Image = Properties.Resources.apk.ToBitmap();
Expand Down Expand Up @@ -214,6 +224,8 @@ private async void btnConnect_Click(object sender, EventArgs e)
if (!ADB.IsStarted) ADB.Start();
await Task.Run(() => ADB.Connect(textIP.Text, textPort.Text));

config.setAdbWifi(textIP.Text, int.Parse(textPort.Text));

setBusy(2, true);
ScanDevice(true);

Expand Down
1 change: 1 addition & 0 deletions Apk_Installer/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<packages>
<package id="Costura.Fody" version="1.6.2" targetFramework="net452" developmentDependency="true" />
<package id="Fody" version="2.0.0" targetFramework="net452" developmentDependency="true" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
<package id="ZipStorer" version="3.3.0" targetFramework="net452" />
</packages>

0 comments on commit 0699337

Please sign in to comment.