Some form of CLI added (wiiNinja style)

This commit is contained in:
givememystuffplease 2010-08-16 23:41:13 +00:00
parent f0a6219e1f
commit 7b173829bc
5 changed files with 157 additions and 18 deletions

View File

@ -424,7 +424,7 @@ namespace NUS_Downloader
// runFolderFixToolStripMenuItem
//
this.runFolderFixToolStripMenuItem.Name = "runFolderFixToolStripMenuItem";
this.runFolderFixToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.runFolderFixToolStripMenuItem.Size = new System.Drawing.Size(144, 22);
this.runFolderFixToolStripMenuItem.Text = "Run \'FolderFix\'";
this.runFolderFixToolStripMenuItem.Click += new System.EventHandler(this.runFolderFixToolStripMenuItem_Click);
//
@ -434,20 +434,20 @@ namespace NUS_Downloader
this.mainPageToolStripMenuItem,
this.databasePageToolStripMenuItem});
this.wiiBrewToolStripMenuItem.Name = "wiiBrewToolStripMenuItem";
this.wiiBrewToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.wiiBrewToolStripMenuItem.Size = new System.Drawing.Size(144, 22);
this.wiiBrewToolStripMenuItem.Text = "WiiBrew";
//
// mainPageToolStripMenuItem
//
this.mainPageToolStripMenuItem.Name = "mainPageToolStripMenuItem";
this.mainPageToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.mainPageToolStripMenuItem.Size = new System.Drawing.Size(147, 22);
this.mainPageToolStripMenuItem.Text = "Main Page";
this.mainPageToolStripMenuItem.Click += new System.EventHandler(this.mainPageToolStripMenuItem_Click);
//
// databasePageToolStripMenuItem
//
this.databasePageToolStripMenuItem.Name = "databasePageToolStripMenuItem";
this.databasePageToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.databasePageToolStripMenuItem.Size = new System.Drawing.Size(147, 22);
this.databasePageToolStripMenuItem.Text = "Database Page";
this.databasePageToolStripMenuItem.Click += new System.EventHandler(this.databasePageToolStripMenuItem_Click);
//
@ -960,7 +960,7 @@ namespace NUS_Downloader
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "NUSD";
this.Text = " ";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
this.Load += new System.EventHandler(this.Form1_Load);
this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseWheel);

View File

@ -104,7 +104,30 @@ namespace NUS_Downloader
GUISetup();
BootChecks();
if ((args.Length == 1) && (File.Exists(args[0])))
{
BootChecks();
string script_content = File.ReadAllText(args[0]);
FileInfo script_file = new FileInfo(args[0]);
script_content += String.Format(";{0}", script_file.Name.Replace("." + script_file.Extension, ""));
BackgroundWorker scripter = new BackgroundWorker();
scripter.DoWork += new DoWorkEventHandler(RunScriptBg);
scripter.RunWorkerAsync(script_content);
}
else if (args.Length >= 2)
{
RunCommandMode(args);
Environment.Exit(0);
//this.Close();
}
else
{
BootChecks();
}
/* Fix proxy entry.
if (!(String.IsNullOrEmpty(proxy_url)))
@ -122,15 +145,86 @@ namespace NUS_Downloader
folder_fixer.RunWorkerAsync();
}*/
if ((args.Length == 1) && (File.Exists(args[0])))
}
private void RunCommandMode(string[] args)
{
// CLI mode, inspired and taken from wiiNinja's mod.
// Initialize the checkboxes and radio boxes
packbox.Checked = false; // Create wad - default OFF
localuse.Checked = true; // Use local content if already downloaded - default ON
decryptbox.Checked = false;
keepenccontents.Checked = false;
consoleCBox.SelectedIndex = 0; // 0 is Wii, 1 is DS
// Clear 3 items in ios patches list. This feature is not supported in the command line version at this time.
iosPatchCheckbox.Checked = false;
iosPatchesListBox.SetItemChecked(0, false);
iosPatchesListBox.SetItemChecked(1, false);
iosPatchesListBox.SetItemChecked(2, false);
Console.WriteLine("NUS Downloader - v{0}", version);
if (args.Length < 2)
{
string script_content = File.ReadAllText(args[0]);
FileInfo script_file = new FileInfo(args[0]);
script_content += String.Format(";{0}", script_file.Name.Replace("." + script_file.Extension, ""));
BackgroundWorker scripter = new BackgroundWorker();
scripter.DoWork += new DoWorkEventHandler(RunScriptBg);
scripter.RunWorkerAsync(script_content);
Console.WriteLine("Usage:");
Console.WriteLine(" nusd <titleID> <titleVersion | *> [optionalArgs]");
Console.WriteLine("\nWhere:");
Console.WriteLine(" titleID = The ID of the title to be downloaded");
Console.WriteLine(" titleVersion = The version of the title to be downloaded");
Console.WriteLine(" Use \"*\" (no quotes) to get the latest version");
Console.WriteLine(" OptionalArgs:");
Console.WriteLine(" packwad = A wad file will be generated");
Console.WriteLine(" localuse = Use local contents if available");
Console.WriteLine(" decrypt = Create decrypted contents");
Console.WriteLine(" keepencrypt = Keep encrypted contents");
}
else
{
for (int i = 0; i < args.Length; i++)
{
Console.WriteLine("{0}", args[i]);
switch (i)
{
case 0:
// First command line argument is ALWAYS the TitleID
titleidbox.Text = args[i];
break;
case 1:
// Second command line argument is ALWAYS the TitleVersion.
// User may specify a "*" to retrieve the latest version
if (args[i] == "*")
titleversion.Text = "";
else
titleversion.Text = args[i];
break;
default:
// Any other arguments beyond the 2nd one are considered optional
if (args[i] == "packwad")
packbox.Checked = true;
else if (args[i] == "localuse")
localuse.Checked = true;
else if (args[i] == "decrypt")
decryptbox.Checked = true;
else if (args[i] == "keepencrypt")
keepenccontents.Checked = true;
else
Console.WriteLine("\n>>>> Warning: Unrecognized command line argument: {0}. This option is ignored...", args[i]);
break;
}
}
// Do this to set the wad file name
UpdatePackedName();
// Call to get the files from server
NUSDownloader_DoWork(null, null);
Console.WriteLine("\nSuccessfully downloaded the title {0} version {1}", args[0], args[1]);
}
}
@ -167,7 +261,6 @@ namespace NUS_Downloader
this.scriptsWorker = new BackgroundWorker();
this.scriptsWorker.DoWork += new DoWorkEventHandler(OrganizeScripts);
this.scriptsWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(scriptsWorker_RunWorkerCompleted);
RunScriptOrganizer();
}
private void Form1_Load(object sender, EventArgs e)
@ -232,6 +325,9 @@ namespace NUS_Downloader
this.fds.RunWorkerAsync();
}
// Load scripts (local)
RunScriptOrganizer();
// Check for Proxy Settings file...
if (NUSDFileExists("proxy.txt") == true)
{
@ -415,6 +511,9 @@ namespace NUS_Downloader
statusbox.SelectionStart = statusbox.TextLength;
statusbox.SelectionLength = 0;
statusbox.ScrollToCaret();
// Also write to console
Console.WriteLine(Update);
}
/// <summary>

View File

@ -6,7 +6,7 @@
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{DB1289FA-BA83-408F-A576-326E5EC4CC6D}</ProjectGuid>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NUS_Downloader</RootNamespace>
<AssemblyName>NUS Downloader</AssemblyName>
@ -59,6 +59,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />

View File

@ -8,23 +8,60 @@
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace NUS_Downloader
{
static class Program
{
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Console.Title = "NUSD";
// hide the console window
setConsoleWindowVisibility(false, Console.Title);
if (args.Length != 0)
{
// hide the console window
setConsoleWindowVisibility(true, Console.Title);
Application.Run(new Form1(args));
}
else
{
// hide the console window
setConsoleWindowVisibility(false, Console.Title);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
public static void setConsoleWindowVisibility(bool visible, string title)
{
//Sometimes System.Windows.Forms.Application.ExecutablePath works for the caption depending on the system you are running under.
IntPtr hWnd = FindWindow(null, title);
if (hWnd != IntPtr.Zero)
{
if (!visible)
//Hide the window
ShowWindow(hWnd, 0); // 0 = SW_HIDE
else
//Show window again
ShowWindow(hWnd, 1); //1 = SW_SHOWNORMA
}
}
}
}