Skip to content

Commit

Permalink
Ad upgrade option on build tools version. Resolve #11
Browse files Browse the repository at this point in the history
  • Loading branch information
equiman committed Nov 1, 2017
1 parent 252087b commit 196f483
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
1 change: 1 addition & 0 deletions dev/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static void Main(string[] args)

//Update Environment Variables
Env.CmdUpdate();
Variables.Upgrade();
Variables.Update();

//Window
Expand Down
4 changes: 3 additions & 1 deletion dev/main/Information.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ public static void Environment() {
Colorify.Default();
Console.Clear();

Variables.Upgrade();
Variables.Update();

Section.Header("ENVIRONMENT VARIABLES");

Variables.Update();
foreach (var v in Variables.list)
{
$"{$" {v.nme}:", -25}".txtPrimary();
Expand Down
29 changes: 27 additions & 2 deletions dev/main/Variable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ public static void Update(){
}
}

public static bool Valid(string opt, bool agn = false)
public static bool Valid(string opt, bool upd = false)
{
var response = false;
try
{
var option = list.Where(x => x.opt == opt).FirstOrDefault();
if (option != null)
{
if (agn || !option.chk){
if (upd || !option.chk){
Check(option);
}
response = option.stt;
Expand Down Expand Up @@ -128,5 +128,30 @@ public static string Value(string opt)
}
return response;
}

public static void Value(string opt, string val)
{
try
{
var option = list.Where(x => x.opt == opt).FirstOrDefault();
if (option != null)
{
Env.Set(option.nme, val);
}
}
catch (Exception Ex){
Exceptions.General(Ex.Message);
}
}

public static void Upgrade(){
try
{
BuildTools.Upgrade();
}
catch (Exception Ex){
Exceptions.General(Ex.Message);
}
}
}
}
4 changes: 4 additions & 0 deletions dev/tools/Machine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public static string Get(string value) {
return Environment.GetEnvironmentVariable(value);
}

public static void Set(string name, string value) {
Environment.SetEnvironmentVariable(name, value);
}

public static bool Check(string value){
string env = Env.Get(value);
return !String.IsNullOrEmpty(env);
Expand Down
30 changes: 30 additions & 0 deletions dev/view/Android.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using dein.tools;

using ct = dein.tools.Colorify.Type;
Expand Down Expand Up @@ -417,5 +419,33 @@ public static void Information() {
Exceptions.General(Ex.Message);
}
}

public static void Upgrade(){
try
{
string currentVersion = Variables.Value("ab");
string lastVersion = "";
string dirPath = Paths.Combine(Variables.Value("ah"), "build-tools");

if (Directory.Exists(dirPath)){
List<string> dirs = new List<string>(Directory.EnumerateDirectories(dirPath));
string d = dirs[dirs.Count - 1].Slash();
lastVersion = d.Substring(d.LastIndexOf("/") + 1);
if (currentVersion != lastVersion){
StringBuilder msg = new StringBuilder();
msg.Append($"There is a new Android Build Tools version installed.");
msg.Append(Environment.NewLine);
msg.Append($" Do you want upgrade ANDROID_BT_VERSION from {currentVersion} to {lastVersion}?");
bool change = Message.Confirmation(msg.ToString());
if (change){
Variables.Value("ab", lastVersion);
}
}
}
}
catch (Exception Ex){
Exceptions.General(Ex.Message);
}
}
}
}

0 comments on commit 196f483

Please sign in to comment.