// true for write, for read its true if the same.. static bool WriteOrCheckSHAFile(DownloadItem it, ConditionVariables vars, string appfolder, bool write) { try { List <string> filelist = new List <string>() { it.localfilename }; foreach (string key in vars.NameEnumuerable) // these first, they are not the controller files { if (key.StartsWith("OtherFile")) { string[] parts = vars[key].Split(';'); string o = Path.Combine(new string[] { appfolder, parts[1], parts[0] }); filelist.Add(o); } } string shacurrent = GitHubClass.CalcSha1(filelist.ToArray()); string shafile = Path.Combine(it.localpath, it.itemname + ".sha"); if (write) { using (StreamWriter sr = new StreamWriter(shafile)) // read directly from file.. { sr.Write(shacurrent); } return(true); } else { if (File.Exists(shafile)) // if there is no SHA file, its local, prob under dev, so its false. SHA is only written by install { using (StreamReader sr = new StreamReader(shafile)) // read directly from file.. { string shastored = sr.ReadToEnd(); sr.Close(); if (shastored.Equals(shacurrent)) { return(true); } } } } } catch { System.Diagnostics.Debug.WriteLine("BUG BUG"); } return(false); }
public bool DownloadFromGitHub(string downloadfolder, string gitdir) { DirectoryInfo di = new DirectoryInfo(downloadfolder); foreach (FileInfo file in di.GetFiles()) { file.Delete(); } GitHubClass ghc = new GitHubClass(); List <GitHubFile> files = ghc.GetDataFiles(gitdir); return(ghc.DownloadFiles(files, downloadfolder)); }
static void Main(string[] args) { GitHubClass p = new GitHubClass("https://api.github.com/repos/EDDiscovery/EDDiscovery/"); JArray r = p.GetAllReleases(100); //string releases = File.ReadAllText(@"c:\code\releases.txt"); //JArray r = JArray.Parse(releases); foreach (JObject t in r) { var url = t["url"].Value <string>(); var tag = t["tag_name"].Value <string>(); var name = t["name"].Value <string>(); var pdate = t["published_at"].Value <DateTime>(); Console.Write("\"" + tag + "\",\"" + name + "\"," + pdate); int downloadeddiscovery = 0; int downloadportable = 0; JArray assets = t["assets"] as JArray; foreach (JObject asset in assets) { var aname = asset["name"].Value <string>(); var download = asset["download_count"].Value <int>(); if (aname.Contains(".exe")) { downloadeddiscovery = download; } else { downloadportable = download; } } Console.Write("," + downloadeddiscovery + "," + downloadportable); Console.WriteLine(""); } }