// in its own thread.. public static Task <bool> DownloadMaps(IDiscoveryController discoveryform, Func <bool> cancelRequested, Action <string> logLine, Action <string> logError) // ASYNC process { try { string mapsdir = Path.Combine(EDDOptions.Instance.AppDataDirectory, "Maps"); if (!Directory.Exists(mapsdir)) { Directory.CreateDirectory(mapsdir); } logLine("Checking for new EDDiscovery maps"); BaseUtils.GitHubClass github = new BaseUtils.GitHubClass(EDDiscovery.Properties.Resources.URLGithubDataDownload, discoveryform.LogLine); var files = github.ReadDirectory("Maps/V1"); return(Task.Factory.StartNew(() => github.DownloadFiles(files, mapsdir))); } catch (Exception ex) { logError("DownloadImages exception: " + ex.Message); var tcs = new TaskCompletionSource <bool>(); tcs.SetException(ex); return(tcs.Task); } }
// in its own thread.. public void DownloadExpeditions(Func <bool> cancelRequested) { LogLine("Checking for new Expedition data"); Task.Factory.StartNew(() => { BaseUtils.GitHubClass github = new BaseUtils.GitHubClass(EDDiscovery.Properties.Resources.URLGithubDataDownload, LogLine); var files = github.ReadDirectory("Expeditions"); if (files != null) // may be empty, unlikely, but { string expeditiondir = Path.Combine(EDDOptions.Instance.AppDataDirectory, "Expeditions"); if (!Directory.Exists(expeditiondir)) { Directory.CreateDirectory(expeditiondir); } if (github.DownloadFiles(files, expeditiondir)) { if (!cancelRequested()) { bool changed = SavedRouteClass.UpdateDBFromExpeditionFiles(expeditiondir); InvokeAsyncOnUiThread(() => { OnExpeditionsDownloaded?.Invoke(changed); }); } } } }); }
// in its own thread.. public void DownloadMaps(Func <bool> cancelRequested) { LogLine("Checking for new EDDiscovery maps"); Task.Factory.StartNew(() => { BaseUtils.GitHubClass github = new BaseUtils.GitHubClass(EDDiscovery.Properties.Resources.URLGithubDataDownload, LogLine); var files = github.ReadDirectory("Maps/V1"); if (files != null) { string mapsdir = Path.Combine(EDDOptions.Instance.AppDataDirectory, "Maps"); if (!Directory.Exists(mapsdir)) { Directory.CreateDirectory(mapsdir); } if (github.DownloadFiles(files, mapsdir)) { if (!cancelRequested()) { InvokeAsyncOnUiThread(() => { OnMapsDownloaded?.Invoke(); }); } } } }); }
public void DownloadHelp(Func <bool> cancelRequested) { Task.Factory.StartNew(() => { string helpdir = EDDOptions.Instance.HelpDirectory(); BaseUtils.GitHubClass github = new BaseUtils.GitHubClass(EDDiscovery.Properties.Resources.URLGithubDataDownload, LogLine); var files = github.ReadDirectory("Help"); if (files != null) // may be empty, unlikely, but { if (github.DownloadFiles(files, helpdir)) { if (!cancelRequested()) { InvokeAsyncOnUiThread(() => { OnHelpDownloaded?.Invoke(); }); } } } }); }
public void DownloadExploration(Func <bool> cancelRequested) { LogLine("Checking for new Exploration data".Tx(this, "EXPL")); Task.Factory.StartNew(() => { string explorationdir = EDDOptions.Instance.ExploreAppDirectory(); BaseUtils.GitHubClass github = new BaseUtils.GitHubClass(EDDiscovery.Properties.Resources.URLGithubDataDownload, LogLine); var files = github.ReadDirectory("Exploration"); if (files != null) // may be empty, unlikely, but { if (github.DownloadFiles(files, explorationdir)) { if (!cancelRequested()) { InvokeAsyncOnUiThread(() => { OnExplorationDownloaded?.Invoke(); }); } } } }); }
public override bool ExecuteAction(ActionProgramRun ap) { List <string> ctrl = FromString(UserData); if (ctrl != null) { List <string> exp; if (ap.Functions.ExpandStrings(ctrl, out exp) != Functions.ExpandResult.Failed) { string cmdname = exp[0].ToLowerInvariant(); string nextword = exp.Count >= 2 ? exp[1] : null; string thirdword = exp.Count >= 3 ? exp[2] : null; string fourthword = exp.Count >= 4 ? exp[3] : null; string fifthword = exp.Count >= 5 ? exp[4] : null; if (cmdname == null) { ap.ReportError("Missing command in Perform"); } else if (cmdname.Equals("3dmap")) { (ap.ActionController as ActionController).DiscoveryForm.Open3DMap(null); } else if (cmdname.Equals("2dmap")) { (ap.ActionController as ActionController).DiscoveryForm.PopOuts.PopOut(PanelInformation.PanelIDs.Map2D); } else if (cmdname.Equals("edsm")) { ActionController ac = (ap.ActionController as ActionController); EliteDangerousCore.EDSM.EDSMClass edsm = new EliteDangerousCore.EDSM.EDSMClass(); if (edsm.ValidCredentials) { ac.DiscoveryForm.EDSMSend(); } else { ap.ReportError("No valid EDSM Credentials"); } } else if (cmdname.Equals("refresh")) { (ap.ActionController as ActionController).DiscoveryForm.RefreshHistoryAsync(); } else if (cmdname.Equals("url")) { if (nextword != null && nextword.StartsWith("http:", StringComparison.InvariantCultureIgnoreCase) || nextword.StartsWith("https:", StringComparison.InvariantCultureIgnoreCase)) // security.. { System.Diagnostics.Process.Start(nextword); } else { ap.ReportError("Perform url must start with http"); } } else if (cmdname.Equals("configurevoice")) { (ap.ActionController as ActionController).ConfigureVoice(nextword ?? "Configure Voice Synthesis"); } else if (cmdname.Equals("manageaddons")) { (ap.ActionController as ActionController).ManageAddOns(); } else if (cmdname.Equals("editaddons")) { (ap.ActionController as ActionController).EditAddOns(); } else if (cmdname.Equals("editlastpack")) { (ap.ActionController as ActionController).EditLastPack(); } else if (cmdname.Equals("editpack")) { if (nextword != null) { if (!(ap.ActionController as ActionController).EditPack(nextword)) { ap.ReportError("Pack " + nextword + " not found"); } } else { ap.ReportError("EditPack requires a pack name"); } } else if (cmdname.Equals("editspeechtext")) { (ap.ActionController as ActionController).EditSpeechText(); } else if (cmdname.Equals("configurewave")) { (ap.ActionController as ActionController).ConfigureWave(nextword ?? "Configure Wave Output"); } else if (cmdname.Equals("enableeliteinput")) { (ap.ActionController as ActionController).EliteInput(true, true); } else if (cmdname.Equals("enableeliteinputnoaxis")) { (ap.ActionController as ActionController).EliteInput(true, false); } else if (cmdname.Equals("disableeliteinput")) { (ap.ActionController as ActionController).EliteInput(false, false); } else if (cmdname.Equals("enablevoicerecognition")) { if (nextword != null) { ap["VoiceRecognitionEnabled"] = ((ap.ActionController as ActionController).VoiceReconOn(nextword)).ToStringIntValue(); } else { ap.ReportError("EnableVoiceRecognition requires a culture"); } } else if (cmdname.Equals("disablevoicerecognition")) { (ap.ActionController as ActionController).VoiceReconOff(); } else if (cmdname.Equals("beginvoicerecognition")) { (ap.ActionController as ActionController).VoiceLoadEvents(); } else if (cmdname.Equals("voicerecognitionconfidencelevel")) { float?conf = nextword.InvariantParseFloatNull(); if (conf != null) { (ap.ActionController as ActionController).VoiceReconConfidence(conf.Value); } else { ap.ReportError("VoiceRecognitionConfidencelLevel requires a confidence value"); } } else if (cmdname.Equals("voicerecognitionparameters")) { int?babble = nextword.InvariantParseIntNull(); // babble at end int?initialsilence = thirdword.InvariantParseIntNull(); // silence at end int?endsilence = fourthword.InvariantParseIntNull(); // unambigious timeout int?endsilenceambigious = fifthword.InvariantParseIntNull(); // ambiguous timeout if (babble != null && initialsilence != null && endsilence != null && endsilenceambigious != null) { (ap.ActionController as ActionController).VoiceReconParameters(babble.Value, initialsilence.Value, endsilence.Value, endsilenceambigious.Value); } else { ap.ReportError("VoiceRecognitionParameters requires four values"); } } else if (cmdname.Equals("voicerecognitionphrases")) { ap["Phrases"] = (ap.ActionController as ActionController).VoicePhrases(Environment.NewLine); } else if (cmdname.Equals("listeliteinput")) { ap["EliteInput"] = (ap.ActionController as ActionController).EliteInputList(); ap["EliteInputCheck"] = (ap.ActionController as ActionController).EliteInputCheck(); } else if (cmdname.Equals("voicenames")) { ap["VoiceNames"] = (ap.ActionController as ActionController).SpeechSynthesizer.GetVoiceNames().QuoteStrings(); } else if (cmdname.Equals("bindings")) { ap["Bindings"] = (ap.ActionController as ActionController).FrontierBindings.ListBindings(); } else if (cmdname.Equals("bindingvalues")) { ap["BindingValues"] = (ap.ActionController as ActionController).FrontierBindings.ListValues(); } else if (cmdname.Equals("actionfile")) { ActionFile f = (ap.ActionController as ActionController).Get(nextword); if (f != null) { int i = 0; foreach (var x in f.EventList.Enumerable) { ap["Events[" + i++ + "]"] = x.ToString(true); // list hooked events ap["Events_" + x.eventname] = x.ToString(true); // list hooked events } i = 0; foreach (string jname in Enum.GetNames(typeof(EliteDangerousCore.JournalTypeEnum))) { List <Condition> cl = f.EventList.GetConditionListByEventName(jname); if (cl != null) { int v = 0; foreach (var c in cl) { ap["JEvents[" + i++ + "]"] = c.ToString(true); ap["JEvents_" + c.eventname + "_" + v++] = c.ToString(true); } } else { ap["JEvents[" + i++ + "]"] = jname + ", None"; ap["JEvents_" + jname] = "None"; } } i = 0; foreach (string iname in Enum.GetNames(typeof(EliteDangerousCore.UITypeEnum))) { List <Condition> cl = f.EventList.GetConditionListByEventName("UI" + iname); if (cl != null) { int v = 0; foreach (var c in cl) { ap["UIEvents[" + i++ + "]"] = c.ToString(true); ap["UIEvents_" + c.eventname + "_" + v++] = c.ToString(true); } } else { ap["UIEvents[" + i++ + "]"] = iname + ", None"; ap["UIEvents_" + iname] = "None"; } } i = 0; foreach (var x in f.InstallationVariables.NameEnumuerable) { ap["Install[" + i++ + "]"] = x + "," + f.InstallationVariables[x]; // list hooked events } i = 0; foreach (var x in f.FileVariables.NameEnumuerable) { ap["FileVar[" + i++ + "]"] = x + "," + f.FileVariables[x]; // list hooked events } ap["Enabled"] = f.Enabled.ToStringIntValue(); } else { ap.ReportError("Action file " + nextword + " is not loaded"); } } else if (cmdname.Equals("datadownload")) { string gitfolder = nextword; string filewildcard = thirdword; string directory = fourthword; string optclean = fifthword; if (gitfolder != null && filewildcard != null && directory != null) { if (System.IO.Directory.Exists(directory)) { BaseUtils.GitHubClass ghc = new BaseUtils.GitHubClass(EDDiscovery.Properties.Resources.URLGithubDataDownload); bool worked = ghc.Download(directory, gitfolder, filewildcard, optclean != null && optclean == "1"); ap["Downloaded"] = worked.ToStringIntValue(); } else { ap.ReportError("Download folder " + directory + " does not exist"); } } else { ap.ReportError("Missing parameters in Perform Datadownload"); } } else if (cmdname.Equals("generateevent")) { if (nextword != null) { ActionEvent f = ActionEventEDList.EventList(excludejournal: true).Find(x => x.TriggerName.Equals(nextword)); if (f != null) { BaseUtils.Variables c = new BaseUtils.Variables(); for (int w = 2; w < exp.Count; w++) { string vname = exp[w]; int asterisk = vname.IndexOf('*'); if (asterisk >= 0) // pass in name* no complaining if not there { string prefix = vname.Substring(0, asterisk); foreach (string jkey in ap.variables.NameEnumuerable) { if (jkey.StartsWith(prefix)) { c[jkey] = ap.variables[jkey]; } } } else { if (ap.variables.Exists(vname)) // pass in explicit name { c[vname] = ap.variables[vname]; } else { ap.ReportError("No such variable '" + vname + "'"); return(true); } } } if (f.TriggerName.StartsWith("UI") || f.TriggerName.Equals("onEliteUIEvent")) { c["EventClass_EventTimeUTC"] = DateTime.UtcNow.ToStringUS(); c["EventClass_EventTypeID"] = c["EventClass_EventTypeStr"] = f.TriggerName.Substring(2); c["EventClass_UIDisplayed"] = "0"; (ap.ActionController as ActionController).ActionRun(Actions.ActionEventEDList.onUIEvent, c); } (ap.ActionController as ActionController).ActionRun(f, c, now: true); } else { try { EliteDangerousCore.JournalEntry je = EliteDangerousCore.JournalEntry.CreateJournalEntry(nextword); ap["GenerateEventName"] = je.EventTypeStr; if (je is EliteDangerousCore.JournalEvents.JournalUnknown) { ap.ReportError("Unknown journal event"); } else { EliteDangerousCore.HistoryEntry he = EliteDangerousCore.HistoryEntry.FromJournalEntry(je, null); (ap.ActionController as ActionController).ActionRunOnEntry(he, Actions.ActionEventEDList.NewEntry(he), now: true); } } catch { ap.ReportError("Journal event not in correct JSON form"); } } } else { ap.ReportError("No journal event or event name after GenerateEvent"); } } else { ap.ReportError("Unknown command " + cmdname + " in Performaction"); } } else { ap.ReportError(exp[0]); } } else { ap.ReportError("Perform command line not in correct format"); } return(true); }
public bool InstallFiles(DownloadItem item, string appfolder) { try { List <string[]> downloads = (from k in item.downloadedvars.NameEnumuerable where k.StartsWith("OtherFile") select item.downloadedvars[k].Split(';')).ToList(); if (downloads.Count > 0) // we have downloads.. { List <string> files = (from a in downloads where a.Length == 2 select a[0]).ToList(); // split them apart and get file names BaseUtils.GitHubClass ghc = new BaseUtils.GitHubClass(item.downloadedserver); string tempfolder = Path.GetTempPath(); if (ghc.Download(tempfolder, item.downloadedserverpath, files)) // download to temp folder.. { foreach (string[] entry in downloads) // copy in { if (entry.Length == 2) { string folder = Path.Combine(appfolder, entry[1]); if (!Directory.Exists(folder)) // ensure the folder exists { Directory.CreateDirectory(folder); } string outfile = Path.Combine(folder, entry[0]); string source = Path.Combine(tempfolder, entry[0]); System.Diagnostics.Debug.WriteLine("Downloaded and installed " + outfile); File.Copy(source, outfile, true); } } } else { return(false); } } foreach (string key in item.downloadedvars.NameEnumuerable) // these first, they are not the controller files { if (key.StartsWith("DisableOther")) { DownloadItem other = downloaditems.Find(x => x.itemname.Equals(item.downloadedvars[key])); if (other != null && other.localfilename != null) { SetEnableFlag(other, false, appfolder); // don't worry if it fails.. } } } File.Copy(item.downloadedfilename, item.localfilename, true); WriteOrCheckSHAFile(item, item.downloadedvars, appfolder, true); return(true); } catch { return(false); } }
public override bool ExecuteAction(ActionProgramRun ap) { string res; if (ap.functions.ExpandString(UserData, out res) != Conditions.ConditionFunctions.ExpandResult.Failed) { StringParser sp = new StringParser(res); string cmdname = sp.NextWord(" ", lowercase: true); if (cmdname == null) { ap.ReportError("Missing command in Perform"); } else if (cmdname.Equals("3dmap")) { (ap.actioncontroller as ActionController).DiscoveryForm.Open3DMap(null); } else if (cmdname.Equals("2dmap")) { (ap.actioncontroller as ActionController).DiscoveryForm.Open2DMap(); } else if (cmdname.Equals("edsm")) { ActionController ac = (ap.actioncontroller as ActionController); EliteDangerousCore.EDSM.EDSMClass edsm = new EliteDangerousCore.EDSM.EDSMClass(); if (edsm.ValidCredentials) { EliteDangerousCore.EDSM.EDSMJournalSync.SendEDSMEvents(ap.actioncontroller.LogLine, ac.DiscoveryForm.history); } else { ap.ReportError("No valid EDSM Credentials"); } } else if (cmdname.Equals("refresh")) { (ap.actioncontroller as ActionController).DiscoveryForm.RefreshHistoryAsync(); } else if (cmdname.Equals("url")) { string url = sp.LineLeft; if (url.StartsWith("http:", StringComparison.InvariantCultureIgnoreCase) || url.StartsWith("https:", StringComparison.InvariantCultureIgnoreCase)) // security.. { System.Diagnostics.Process.Start(url); } else { ap.ReportError("Perform url must start with http"); } } else if (cmdname.Equals("configurevoice")) { (ap.actioncontroller as ActionController).ConfigureVoice(sp.NextQuotedWord() ?? "Configure Voice Synthesis"); } else if (cmdname.Equals("manageaddons")) { (ap.actioncontroller as ActionController).ManageAddOns(); } else if (cmdname.Equals("editaddons")) { (ap.actioncontroller as ActionController).EditAddOns(); } else if (cmdname.Equals("editlastpack")) { (ap.actioncontroller as ActionController).EditLastPack(); } else if (cmdname.Equals("editpack")) { string pack = sp.NextQuotedWord(); if (pack != null) { if (!(ap.actioncontroller as ActionController).EditPack(pack)) { ap.ReportError("Pack " + pack + " not found"); } } else { ap.ReportError("EditPack requires a pack name"); } } else if (cmdname.Equals("editspeechtext")) { (ap.actioncontroller as ActionController).EditSpeechText(); } else if (cmdname.Equals("configurewave")) { (ap.actioncontroller as ActionController).ConfigureWave(sp.NextQuotedWord() ?? "Configure Wave Output"); } else if (cmdname.Equals("enableeliteinput")) { (ap.actioncontroller as ActionController).EliteInput(true, true); } else if (cmdname.Equals("enableeliteinputnoaxis")) { (ap.actioncontroller as ActionController).EliteInput(true, false); } else if (cmdname.Equals("disableeliteinput")) { (ap.actioncontroller as ActionController).EliteInput(false, false); } else if (cmdname.Equals("enablevoicerecognition")) { string culture = sp.NextQuotedWord(); if (culture != null) { ap["VoiceRecognitionEnabled"] = ((ap.actioncontroller as ActionController).VoiceReconOn(culture)).ToStringIntValue(); } else { ap.ReportError("EnableVoiceRecognition requires a culture"); } } else if (cmdname.Equals("disablevoicerecognition")) { (ap.actioncontroller as ActionController).VoiceReconOff(); } else if (cmdname.Equals("beginvoicerecognition")) { (ap.actioncontroller as ActionController).VoiceLoadEvents(); } else if (cmdname.Equals("voicerecognitionconfidencelevel")) { float?conf = sp.NextWord().InvariantParseFloatNull(); if (conf != null) { (ap.actioncontroller as ActionController).VoiceReconConfidence(conf.Value); } else { ap.ReportError("VoiceRecognitionConfidencelLevel requires a confidence value"); } } else if (cmdname.Equals("voicerecognitionparameters")) { int?babble = sp.NextWordComma().InvariantParseIntNull(); // babble at end int?initialsilence = sp.NextWordComma().InvariantParseIntNull(); // silence at end int?endsilence = sp.NextWordComma().InvariantParseIntNull(); // unambigious timeout int?endsilenceambigious = sp.NextWordComma().InvariantParseIntNull(); // ambiguous timeout if (babble != null && initialsilence != null && endsilence != null && endsilenceambigious != null) { (ap.actioncontroller as ActionController).VoiceReconParameters(babble.Value, initialsilence.Value, endsilence.Value, endsilenceambigious.Value); } else { ap.ReportError("VoiceRecognitionParameters requires four values"); } } else if (cmdname.Equals("voicerecognitionphrases")) { ap["Phrases"] = (ap.actioncontroller as ActionController).VoicePhrases(Environment.NewLine); } else if (cmdname.Equals("listeliteinput")) { ap["EliteInput"] = (ap.actioncontroller as ActionController).EliteInputList(); ap["EliteInputCheck"] = (ap.actioncontroller as ActionController).EliteInputCheck(); } else if (cmdname.Equals("voicenames")) { ap["VoiceNames"] = (ap.actioncontroller as ActionController).SpeechSynthesizer.GetVoiceNames().QuoteStrings(); } else if (cmdname.Equals("bindings")) { ap["Bindings"] = (ap.actioncontroller as ActionController).FrontierBindings.ListBindings(); } else if (cmdname.Equals("bindingvalues")) { ap["BindingValues"] = (ap.actioncontroller as ActionController).FrontierBindings.ListValues(); } else if (cmdname.Equals("datadownload")) { string gitfolder = sp.NextQuotedWord(); string filewildcard = sp.NextQuotedWord(); string directory = sp.NextQuotedWord(); string optclean = sp.NextWord(); if (gitfolder != null && filewildcard != null && directory != null) { if (System.IO.Directory.Exists(directory)) { BaseUtils.GitHubClass ghc = new BaseUtils.GitHubClass(EDDiscovery.Properties.Resources.URLGithubDataDownload); bool worked = ghc.Download(directory, gitfolder, filewildcard, optclean != null && optclean == "1"); ap["Downloaded"] = worked.ToStringIntValue(); } else { ap.ReportError("Download folder " + directory + " does not exist"); } } else { ap.ReportError("Missing parameters in Perform Datadownload"); } } else { ap.ReportError("Unknown command " + cmdname + " in Performaction"); } } else { ap.ReportError(res); } return(true); }