public static int HandleCommandLine(string[] args, string[] options) { bool all = false; foreach (var option in options) { switch (option) { case "--all": all = true; break; default: Console.WriteLine("Invalid option: " + option); return(1); } } var results = KerbalStuff.Search(string.Join(" ", args)); if (!all) { // TODO: Filter out unsupported versions } foreach (var result in results) { Console.WriteLine("{0}/{1} [{2}]", result.Author, result.Name, result.Downloads); Console.WriteLine("\t" + Truncate(result.ShortDescription, Console.WindowWidth - 8)); } return(0); }
public static int HandleCommandLine(string[] args, string[] options) { var terms = string.Join(" ", args); var search = KerbalStuff.Search(terms); var results = search.Where(r => r.Name.ToUpper() == terms.ToUpper() || r.Author.ToUpper() + "/" + r.Name.ToUpper() == terms.ToUpper()); if (!results.Any()) { results = search; } if (results.Count() > 1) { Console.WriteLine("Error: \"{0}\" is ambiguous between:"); foreach (var m in results) { Console.WriteLine("{0}/{1} [{2}]", m.Author, m.Name, m.Downloads); } return(1); } var mod = results.Single(); using (WebClient client = new WebClient()) { string sOutput = String.Format("{0}-{1}.zip", mod.Name, mod.Versions.First().FriendlyVersion); Console.WriteLine("Downloading \"{0}\" to working directory...", sOutput); Console.WriteLine("\tPlease wait ..."); client.DownloadFile(Settings.KS_ROOT + mod.Versions.First().DownloadPaths, sOutput); Console.WriteLine("\nDownload completed Successfully."); } return(0); }
public static int HandleCommandLine(string[] args, string[] options) { var terms = string.Join(" ", args); var search = KerbalStuff.Search(terms); var results = search.Where(r => r.Name.ToUpper() == terms.ToUpper() || r.Author.ToUpper() + "/" + r.Name.ToUpper() == terms.ToUpper()); if (!results.Any()) { results = search; } if (results.Count() > 1) { Console.WriteLine("Error: \"{0}\" is ambiguous between:"); foreach (var m in results) { Console.WriteLine("{0}/{1} [{2}]", m.Author, m.Name, m.Downloads); } return(1); } var mod = results.Single(); Console.WriteLine("{0}/{1}", mod.Author, mod.Name); Console.WriteLine("Name: {0}", mod.Name); Console.WriteLine("Author: {0}", mod.Author); Console.WriteLine("URL: {1}/{0}", mod.Id, Settings.KS_MOD); Console.WriteLine("Version: {0}", mod.Versions[0].FriendlyVersion); Console.WriteLine("Downloads: {0}", mod.Downloads); Console.WriteLine("Followers: {0}", mod.Followers); Console.WriteLine("Short Description: \n\t{0}", mod.ShortDescription); return(0); }
public static void UserInfo([Required] string username) { User user = KerbalStuff.UserInfo(username); if (user == null) { WriteErrorLine("Couldn't get user info for username '{0}': {1}", username, KerbalStuff.currentResponse.StatusDescription); } else { Console.WriteLine(user); } }
public static void ModLatest([Required] long modId) { ModVersion ver = KerbalStuff.ModLatest(modId); if (ver == null) { WriteErrorLine("Couldn't get version info for mod {0}: {1}.", modId, KerbalStuff.currentResponse.StatusDescription); } else { Console.WriteLine(ver); } }
public static void ModInfo([Required] long modId) { Mod mod = KerbalStuff.ModInfo(modId); if (mod == null) { WriteErrorLine("Couldn't get Mod info for mod {0}: {1}.", modId, KerbalStuff.currentResponse.StatusDescription); } else { Console.WriteLine(mod); } }
public static void UserSearch([Required] string query, [DefaultValue(1)] long pageId) { List <User> users = KerbalStuff.UserSearch(query, pageId); if (users.Count < 1) { WriteOutLine("Query yielded no results."); } else { foreach (User user in users) { Console.WriteLine(user); Console.WriteLine(); } } }
public static void ModSearch([Required] string query, [DefaultValue(1)] long pageId) { List <Mod> mods = KerbalStuff.ModSearch(query, pageId); if (mods.Count < 1) { WriteOutLine("Query yielded no results."); } else { foreach (Mod mod in mods) { Console.WriteLine(mod); Console.WriteLine(); } } }
public static void BrowseTop([DefaultValue(1)] long pageId) { List <Mod> mods = KerbalStuff.BrowseTop(pageId); if (mods.Count < 1) { WriteOutLine("Query yielded no results."); } else { foreach (Mod mod in mods) { Console.WriteLine(mod); Console.WriteLine(); } } }
public static int HandleCommandLine(string[] args, string[] options) { var terms = string.Join(" ", args); var search = KerbalStuff.Search(terms); var results = search.Where(r => r.Name.ToUpper() == terms.ToUpper() || r.Author.ToUpper() + "/" + r.Name.ToUpper() == terms.ToUpper()); if (!results.Any()) { results = search; } if (results.Count() > 1) { Console.WriteLine("Error: \"{0}\" is ambiguous between:"); foreach (var m in results) { Console.WriteLine("{0}/{1} [{2}]", m.Author, m.Name, m.Downloads); } return(1); } var mod = results.Single(); foreach (var version in mod.Versions) { Console.WriteLine("== Version {0} (for KSP {1})", version.FriendlyVersion, version.KSPVersion); if (string.IsNullOrEmpty(version.Changelog)) { Console.WriteLine("The first version of {0}", mod.Name); } else { Console.WriteLine(version.Changelog); } Console.WriteLine(); } return(0); }
public static void UpdateMod( [Required] [Aliases("user,u")] string username, [Required] [Aliases("pass,p")] string password, [Required] [Aliases("mod,m")] long modId, [Required] [Aliases("ver,v")] string version, [Required] [Aliases("ksp,k")] string ksp_version, [Aliases("log,l")] string changelog, [DefaultValue(false)] [Aliases("notify,n")] bool notifyFollowers, [Required] [Aliases("file,f")] string filePath ) { ModVersion ver; if (changelog != string.Empty) { ver = new ModVersion(version, ksp_version, changelog); } else { ver = new ModVersion(version, ksp_version); } var loginDict = KerbalStuff.Login(username, password); if (loginDict == null) { WriteErrorLine("Could not complete login attempt: {0}", KerbalStuff.currentResponse.StatusDescription); } else if (loginDict.ContainsKey("error") && loginDict["error"].ToString().ToLower() == "true") { WriteErrorLine("Login failed: {0}", loginDict["reason"]); } else { var updateDict = KerbalStuff.Update(modId, ver, notifyFollowers, Path.GetFileName(filePath), filePath); if (updateDict == null) { WriteErrorLine("Could not complete creation attempt: {0}", KerbalStuff.currentResponse.StatusDescription); } else if (updateDict.ContainsKey("error") && updateDict["error"].ToString().ToLower() == "true") { WriteErrorLine("Creation failed: {0}", updateDict["reason"]); } else { WriteOutLine("Mod #{0}! You can view the update at {1}", updateDict["id"], string.Concat(KerbalStuff.RootUri, updateDict["url"]) ); } } }
public static void CreateMod( [Required] [Aliases("user,u")] string username, [Required] [Aliases("pass,p")] string password, [Required] [Aliases("n")] string name, [Required] [Aliases("desc,d")] string short_description, [Required] [Aliases("ver,v")] string version, [Required] [Aliases("ksp,k")] string ksp_version, [Required] [Aliases("lic,l")] string license, [Required] [Aliases("file,f")] string filePath ) { Mod mod = new Mod(name, short_description, version, ksp_version, license); var loginDict = KerbalStuff.Login(username, password); if (loginDict == null) { WriteErrorLine("Could not complete login attempt: {0}", KerbalStuff.currentResponse.StatusDescription); } else if (loginDict.ContainsKey("error") && loginDict["error"].ToString().ToLower() == "true") { WriteErrorLine("Login failed: {0}", loginDict["reason"]); } else { var createDict = KerbalStuff.Create(mod, Path.GetFileName(filePath), filePath); if (createDict == null) { WriteErrorLine("Could not complete creation attempt: {0}", KerbalStuff.currentResponse.StatusDescription); } else if (createDict.ContainsKey("error") && createDict["error"].ToString().ToLower() == "true") { WriteErrorLine("Creation failed: {0}", createDict["reason"]); } else { WriteOutLine("New mod '{0}' created with id #{2}! You can view and publish the mod at {1}", createDict["name"], string.Concat(KerbalStuff.RootUri, createDict["url"]), createDict["id"] ); } } }
public static void Refresh(RefreshType refreshType = RefreshType.Last) { model.Nodes.Clear(); if (refreshType == RefreshType.Last) { refreshType = LastRefresh; } View.ShowProcessing = true; EventDistributor.InvokeAsyncTaskStarted(Instance); AsyncTask <List <KsMod> > .DoWork( () => { List <KsMod> mods = null; switch (refreshType) { default: case RefreshType.New: mods = KerbalStuff.BrowseNew(View.Page); break; case RefreshType.Top: mods = KerbalStuff.BrowseTop(View.Page); break; case RefreshType.Featured: mods = KerbalStuff.BrowseFeatured(View.Page); break; case RefreshType.Browse: mods = KerbalStuff.Browse(View.Page); break; } return(mods); }, (result, ex) => { View.ShowProcessing = false; EventDistributor.InvokeAsyncTaskDone(Instance); if (ex != null) { Messenger.AddError(string.Format("Error during browsing KerbalStuff! {0}", ex), ex); } else { if (KerbalStuff.LastResponse == null || result == null) { Messenger.AddError("Error during browsing KerbalStuff! Empty result"); return; } View.MaxPages = KerbalStuff.LastResponse.pages; View.CountLabelText = string.Format("Mods per page: {0}", KerbalStuff.LastResponse.count); foreach (var mod in result) { model.Nodes.Add(new KerbalStuffNode(mod)); } } }); }