TransmitMii 1.1

This commit is contained in:
Leathl 2009-12-09 18:58:32 +00:00
parent bf34bcaaae
commit f194600262
13 changed files with 867 additions and 150 deletions

View File

@ -6,13 +6,19 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{70517550-06FA-4743-B5D7-2CB7C153E35E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{70517550-06FA-4743-B5D7-2CB7C153E35E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{70517550-06FA-4743-B5D7-2CB7C153E35E}.Debug|x86.ActiveCfg = Debug|x86
{70517550-06FA-4743-B5D7-2CB7C153E35E}.Debug|x86.Build.0 = Debug|x86
{70517550-06FA-4743-B5D7-2CB7C153E35E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{70517550-06FA-4743-B5D7-2CB7C153E35E}.Release|Any CPU.Build.0 = Release|Any CPU
{70517550-06FA-4743-B5D7-2CB7C153E35E}.Release|x86.ActiveCfg = Release|x86
{70517550-06FA-4743-B5D7-2CB7C153E35E}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -49,5 +49,5 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]

View File

@ -1,4 +1,21 @@
//------------------------------------------------------------------------------
/* This file is part of TransmitMii
* Copyright (C) 2009 Leathl
*
* TransmitMii is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TransmitMii is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
// Laufzeitversion:2.0.50727.4927

View File

@ -1,21 +1,4 @@
/* This file is part of TransmitMii
* Copyright (C) 2009 Leathl
*
* TransmitMii is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TransmitMii is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
// Laufzeitversion:2.0.50727.4927

View File

@ -9,6 +9,10 @@ TransmitMii is hosted on the CustomizeMii project page: http://customizemii.goog
-----------------------------------------------------------------------------------------
Changelog:
Version 1.1
- Added ability to link and unlink extensions with TransmitMii
- Added compression for HBC 1.0.5+ (similar to wiiload)
Version 1.0
- Initial Release
-----------------------------------------------------------------------------------------
@ -25,6 +29,8 @@ Thanks:
dhewg for wiiload
WiiCrazy / I.R.on for Crap
Jean-loup Gailly and Mark Adler for zlib1.dll (zlib)
dillonaumiller for Associaton.cs
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------

View File

@ -15,6 +15,21 @@
<TargetFrameworkSubset>
</TargetFrameworkSubset>
<ApplicationIcon>Resources\TransmitMii Icon.ico</ApplicationIcon>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -24,6 +39,8 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>
</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@ -32,6 +49,24 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>
</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@ -42,6 +77,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="TransmitMii_Associations.cs" />
<Compile Include="TransmitMii_Main.cs">
<SubType>Form</SubType>
</Compile>
@ -73,12 +109,43 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="TransmitMii_Transmit.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="TransmitMii_zlib.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="License.txt" />
<Content Include="Readme.txt" />
<None Include="Resources\TransmitMii Icon.ico" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
<Visible>False</Visible>
<ProductName>.NET Framework 2.0 %28x86%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
<Visible>False</Visible>
<ProductName>.NET Framework 3.0 %28x86%29</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -1 +1,17 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishUrlHistory>publish\</PublishUrlHistory>
<InstallUrlHistory>
</InstallUrlHistory>
<SupportUrlHistory>
</SupportUrlHistory>
<UpdateUrlHistory>
</UpdateUrlHistory>
<BootstrapperUrlHistory>
</BootstrapperUrlHistory>
<ErrorReportUrlHistory>
</ErrorReportUrlHistory>
<FallbackCulture>de-DE</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,245 @@
/* This file is part of TransmitMii (Original code by dillonaumiller, thanks!)
* Copyright (C) 2009 dillonaumiller, Leathl
*
* TransmitMii is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TransmitMii is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace TransmitMii
{
public static class TransmitMii_Associations
{
public enum Extension
{
DOL = 0,
ELF = 1,
Both = 2,
WAD = 3
}
public static string AssociationPath()
{
try { return Registry.GetValue("HKEY_CLASSES_ROOT\\WiiBin\\shell\\sendwii\\command", "", "").ToString().Replace("%1", "").Replace("\"", ""); }
catch { return ""; }
}
public static bool CheckAssociation(Extension which)
{
if (which == Extension.Both)
{
if (Registry.GetValue("HKEY_CLASSES_ROOT\\.dol", "", "").ToString().ToLower() == "wiibin" &&
Registry.GetValue("HKEY_CLASSES_ROOT\\.elf", "", "").ToString().ToLower() == "wiibin") return true;
else return false;
}
string regKey;
if (which == Extension.DOL)
regKey = "HKEY_CLASSES_ROOT\\.dol";
else if (which == Extension.ELF)
regKey = "HKEY_CLASSES_ROOT\\.elf";
else
regKey = "HKEY_CLASSES_ROOT\\.wad";
if (Registry.GetValue(regKey, "", "").ToString().ToLower() != "wiibin") return false;
else return true;
}
public static bool DeleteAssociation(Extension which)
{
try
{
string regKey;
if (which == Extension.DOL)
regKey = "HKEY_CLASSES_ROOT\\.dol";
else if (which == Extension.ELF)
regKey = "HKEY_CLASSES_ROOT\\.elf";
else
regKey = "HKEY_CLASSES_ROOT\\.wad";
if (ValueExists(regKey, ""))
Registry.SetValue(regKey, "", "");
return true;
}
catch { return false; }
}
public static bool AddAssociation(Extension which, bool makeDefault, string iconPath, bool updateIconCache)
{
//-------
//OPTIONS
//-------
//if(makeDefault) then "Send to Wii" will be the default action for this file type
//if((iconPath == null) || (iconPath == "")) then we won't create a "DefaultIcon" entry for this type
//if(updateIconCache) then force explorer to update it's icon cache (without a logout/login cycle), NOTE: this has a side affect of possibly losing custom desktop icon positions
if ((which == Extension.DOL) || (which == Extension.Both))
if (AddExtension("dol", makeDefault, iconPath) == false)
return false;
if ((which == Extension.ELF) || (which == Extension.Both))
if (AddExtension("elf", makeDefault, iconPath) == false)
return false;
if (which == Extension.WAD)
if (AddExtension("wad", makeDefault, iconPath) == false)
return false;
//get explorer to re-draw the new icon, if needed
if(updateIconCache)
UpdateExplorerIconCache();
return true;
}
//==========================================================================
// private code
//==========================================================================
static bool AddExtension(string extension, bool makeDefault, string iconPath)
{
bool createClass = true;
string rkEXT = "HKEY_CLASSES_ROOT\\." + extension;
string rkCLS = "HKEY_CLASSES_ROOT\\WiiBin";
//check if the file-type already has a class
if (ValueExists(rkEXT, ""))
{
string currClass = (string)Registry.GetValue(rkEXT, "", "");
if (currClass.Trim().Length > 0)
{
rkCLS = "HKEY_CLASSES_ROOT\\" + currClass;
if (ValueExists(rkCLS, "")) //exists, and is valid
createClass = false;
}
else //we need to create an entry for this filetype
if (KeyCreate(rkEXT, "WiiBin") == false)
return false;
}
else //we need to create an entry for this filetype
if (KeyCreate(rkEXT, "WiiBin") == false)
return false;
if(createClass) //then we'll be using our own "WiiBin" class
{
//create main key
if (KeyCreate(rkCLS, "Wii Binary Image") == false)
return false;
//create "DefaultIcon" subkey
if (iconPath != null)
if (iconPath != "")
if (KeyCreate(rkCLS + "\\DefaultIcon", iconPath) == false)
return false;
//create "Shell" subkey
if (KeyCreate(rkCLS + "\\shell", "") == false)
return false;
}
//set default icon if desired
if (iconPath != null)
if (iconPath != "")
if (SetStringValue(rkCLS + "\\DefaultIcon", "", iconPath) == false)
return false;
//set default action if desired
if (makeDefault)
if (SetStringValue(rkCLS + "\\shell", "", "sendwii") == false)
return false;
//create "Shell\\sendwii" subkey
if (KeyCreate(rkCLS + "\\shell\\sendwii", "Send to Wii") == false)
return false;
//create "Shell\\sendwii\\command
if (KeyCreate(rkCLS + "\\shell\\sendwii\\command", "\"" + System.Reflection.Assembly.GetExecutingAssembly().Location + "\" \"%1\"") == false)
return false;
return true;
}
static bool ValueExists(string key, string value)
{
if (Registry.GetValue(key, value, null) == null)
return false;
return true;
}
static bool KeyCreate(string key, object defaultValue)
{
try
{
Registry.SetValue(key, "", defaultValue);
return true;
}
catch(Exception)
{
return false;
}
}
static bool SetStringValue(string key, string value, string data)
{
try
{
Registry.SetValue(key, value, data);
return true;
}
catch(Exception)
{
return false;
}
}
[DllImport("user32.dll")] static extern long SendMessageTimeout(int hWnd, int Msg, int wParam, string lParam, int fuFlags, int uTimeout, out int lpdwResult);
static void UpdateExplorerIconCache()
{
string currMetricVal = (string)Registry.GetValue("HKEY_CURRENT_USER\\Control Panel\\Desktop\\WindowMetrics", "Shell Icon Size", null);
if (currMetricVal == null)
return; //how the hell did this happen?
int iSize;
try
{
iSize = int.Parse(currMetricVal) + 1;
}
catch (Exception)
{
iSize = 31;
}
RegistryKey siz;
int res = 0;
siz = Registry.CurrentUser.OpenSubKey("Control Panel").OpenSubKey("Desktop").OpenSubKey("WindowMetrics", true);
siz.SetValue("Shell Icon Size", iSize.ToString());
siz.Flush();
siz.Close();
SendMessageTimeout(0xFFFF, 0x001A, 0, "", 0, 100, out res);
siz = Registry.CurrentUser.OpenSubKey("Control Panel").OpenSubKey("Desktop").OpenSubKey("WindowMetrics", true);
siz.SetValue("Shell Icon Size", currMetricVal);
siz.Flush();
siz.Close();
SendMessageTimeout(0xFFFF, 0x001A, 0, "", 0, 100, out res);
}
}
}

View File

@ -54,6 +54,7 @@ namespace TransmitMii
this.tbIP = new System.Windows.Forms.TextBox();
this.lbProtocol = new System.Windows.Forms.Label();
this.cmbProtocol = new System.Windows.Forms.ComboBox();
this.llbLinkExtension = new System.Windows.Forms.LinkLabel();
this.SuspendLayout();
//
// lbIP
@ -145,12 +146,26 @@ namespace TransmitMii
this.cmbProtocol.MouseEnter += new System.EventHandler(this.cmbProtocol_MouseEnter);
this.cmbProtocol.MouseLeave += new System.EventHandler(this.cmbProtocol_MouseLeave);
//
// llbLinkExtension
//
this.llbLinkExtension.AutoSize = true;
this.llbLinkExtension.Location = new System.Drawing.Point(215, 108);
this.llbLinkExtension.Name = "llbLinkExtension";
this.llbLinkExtension.Size = new System.Drawing.Size(76, 13);
this.llbLinkExtension.TabIndex = 11;
this.llbLinkExtension.TabStop = true;
this.llbLinkExtension.Text = "Link Extension";
this.llbLinkExtension.MouseLeave += new System.EventHandler(this.llbLinkExtension_MouseLeave);
this.llbLinkExtension.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.llbLinkExtension_LinkClicked);
this.llbLinkExtension.MouseEnter += new System.EventHandler(this.llbLinkExtension_MouseEnter);
//
// TransmitMii_Main
//
this.AllowDrop = true;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(303, 128);
this.Controls.Add(this.llbLinkExtension);
this.Controls.Add(this.cmbProtocol);
this.Controls.Add(this.lbProtocol);
this.Controls.Add(this.tbIP);
@ -184,6 +199,7 @@ namespace TransmitMii
private System.Windows.Forms.TextBox tbIP;
private System.Windows.Forms.Label lbProtocol;
private System.Windows.Forms.ComboBox cmbProtocol;
private System.Windows.Forms.LinkLabel llbLinkExtension;
}
}

View File

@ -19,9 +19,7 @@ using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Net.Sockets;
using System.Text.RegularExpressions;
using System.Windows.Forms;
@ -29,11 +27,13 @@ namespace TransmitMii
{
public partial class TransmitMii_Main : Form
{
const string version = "1.0"; //Hint for myself: Never use a char in the Version (UpdateCheck)!
const string version = "1.1"; //Hint for myself: Never use a char in the Version (UpdateCheck)!
private bool IsRunning = false;
private string fileName;
private string statusText;
private bool JODI;
private bool Aborted = false;
private bool directStart = false;
EventHandler UpdateStatus;
EventHandler EnableButtons;
BackgroundWorker bwTransmit = new BackgroundWorker();
@ -43,7 +43,6 @@ namespace TransmitMii
{
InitializeComponent();
this.CenterToScreen();
this.Icon = Properties.Resources.TransmitMii_Icon;
}
public TransmitMii_Main(string[] args)
@ -51,17 +50,23 @@ namespace TransmitMii
InitializeComponent();
this.CenterToScreen();
if (args[0].EndsWith(".dol") || args[0].EndsWith(".elf"))
if (args[0].EndsWith(".dol") || args[0].EndsWith(".elf") || args[0].EndsWith(".wad"))
{
tbFile.Text = args[0];
directStart = true;
}
}
private void TransmitMii_Main_Load(object sender, EventArgs e)
{
this.Text = this.Text.Replace("X", version);
this.Icon = Properties.Resources.TransmitMii_Icon;
UpdateCheck();
ExtensionCheck();
UpdateStatus = new EventHandler(this.StatusUpdate);
EnableButtons = new EventHandler(this.ButtonEnable);
bwTransmit.DoWork += new DoWorkEventHandler(bwTransmit_DoWork);
bwTransmit.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bwTransmit_RunWorkerCompleted);
bwTransmit.WorkerSupportsCancellation = true;
@ -74,7 +79,7 @@ namespace TransmitMii
LoadSettings();
if (!string.IsNullOrEmpty(tbIP.Text) && !string.IsNullOrEmpty(tbFile.Text))
if ((!string.IsNullOrEmpty(tbIP.Text) && !string.IsNullOrEmpty(tbFile.Text)) && directStart)
btnSend_Click(null, null);
}
@ -115,6 +120,23 @@ namespace TransmitMii
catch { }
}
private void ExtensionCheck()
{
string oldPath = TransmitMii_Associations.AssociationPath().ToLower();
string newPath = Application.ExecutablePath.ToLower();
if (!string.IsNullOrEmpty(oldPath) && !string.IsNullOrEmpty(newPath))
{
if (oldPath != newPath)
{
if (TransmitMii_Associations.CheckAssociation(TransmitMii_Associations.Extension.DOL))
TransmitMii_Associations.AddAssociation(TransmitMii_Associations.Extension.DOL, true, newPath, false);
if (TransmitMii_Associations.CheckAssociation(TransmitMii_Associations.Extension.ELF))
TransmitMii_Associations.AddAssociation(TransmitMii_Associations.Extension.ELF, true, newPath, false);
}
}
}
private void ErrorBox(string message)
{
MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
@ -135,107 +157,7 @@ namespace TransmitMii
{
IsRunning = false;
btnBrowseFile.Enabled = true;
btnSend.Enabled = true;
}
private bool Transmit(string fileName, byte[] fileData, bool JODI) //(byte[] theFile, int fileLength, byte[] args, int argsLength)
{
TcpClient theClient = new TcpClient();
NetworkStream theStream;
int Blocksize = 4 * 1024;
if (!JODI) Blocksize = 16 * 1024;
byte[] buffer = new byte[4];
string theIP = tbIP.Text;
StatusUpdate("Connecting...");
try { theClient.Connect(theIP, 4299); }
catch (Exception ex) { ErrorBox("Connection Failed:\n" + ex.Message); theClient.Close(); return false; }
theStream = theClient.GetStream();
StatusUpdate("Connected... Sending Magic...");
buffer[0] = (byte)'H';
buffer[1] = (byte)'A';
buffer[2] = (byte)'X';
buffer[3] = (byte)'X';
try { theStream.Write(buffer, 0, 4); }
catch (Exception ex) { ErrorBox("Error sending Magic:\n" + ex.Message); theStream.Close(); theClient.Close(); return false; }
StatusUpdate("Magic Sent... Sending Version Info...");
if (JODI)
{
buffer[0] = 0;
buffer[1] = 5;
buffer[2] = (byte)(((fileName.Length + 2) >> 8) & 0xff);
buffer[3] = (byte)((fileName.Length + 2) & 0xff);
}
else
{
buffer[0] = 0;
buffer[1] = 1;
buffer[2] = 0;
buffer[3] = 0;
}
try { theStream.Write(buffer, 0, 4); }
catch (Exception ex) { ErrorBox("Error sending Version Info:\n" + ex.Message); theStream.Close(); theClient.Close(); return false; }
StatusUpdate("Version Info Sent... Sending Filesize...");
//First compressed filesize, then uncompressed filesize
buffer[0] = (byte)((fileData.Length >> 24) & 0xff);
buffer[1] = (byte)((fileData.Length >> 16) & 0xff);
buffer[2] = (byte)((fileData.Length >> 8) & 0xff);
buffer[3] = (byte)(fileData.Length & 0xff);
try { theStream.Write(buffer, 0, 4); }
catch (Exception ex) { ErrorBox("Error sending Filesize:\n" + ex.Message); theStream.Close(); theClient.Close(); return false; }
if (JODI)
{
buffer[0] = 0;
buffer[1] = 0;
buffer[2] = 0;
buffer[3] = 0;
try { theStream.Write(buffer, 0, 4); }
catch (Exception ex) { ErrorBox("Error sending Filesize:\n" + ex.Message); theStream.Close(); theClient.Close(); return false; }
}
StatusUpdate("Filesize Sent... Sending File...");
int off = 0;
int cur = 0;
int count = fileData.Length / Blocksize;
int left = fileData.Length % Blocksize;
try
{
do
{
StatusUpdate("Sending File: " + ((cur + 1) * 100 / count).ToString() + "%");
theStream.Write(fileData, off, Blocksize);
off += Blocksize;
cur++;
} while (cur < count);
if (left > 0)
{
theStream.Write(fileData, off, fileData.Length - off);
}
}
catch (Exception ex) { ErrorBox("Error sending File:\n" + ex.Message); theStream.Close(); theClient.Close(); return false; }
if (JODI)
{
StatusUpdate("File Sent... Sending Arguments...");
byte[] theArgs = new byte[fileName.Length + 2];
for (int i = 0; i < fileName.Length; i++) { theArgs[i] = (byte)fileName.ToCharArray()[i]; }
try { theStream.Write(theArgs, 0, theArgs.Length); }
catch (Exception ex) { ErrorBox("Error sending Arguments:\n" + ex.Message); theStream.Close(); theClient.Close(); return false; }
}
theStream.Close();
theClient.Close();
StatusUpdate(string.Empty);
return true;
btnSend.Text = "Send";
}
private void btnBrowseFile_Click(object sender, EventArgs e)
@ -252,29 +174,61 @@ namespace TransmitMii
private void btnSend_Click(object sender, EventArgs e)
{
if (File.Exists(tbFile.Text))
if (btnSend.Text == "Abort")
{
if (IpAdress.IsMatch(tbIP.Text))
{
if (tbFile.Text.EndsWith(".wad") && cmbProtocol.SelectedIndex != 2)
{ ErrorBox("WAD files can only be sent to USB Loader GX!"); return; }
Aborted = true;
btnSend.Enabled = false;
btnBrowseFile.Enabled = false;
IsRunning = true;
bwTransmit.CancelAsync();
FileStream fs = new FileStream(tbFile.Text, FileMode.Open);
byte[] theFile = new byte[fs.Length];
fs.Read(theFile, 0, theFile.Length);
try { theStream.Close(); ; }
catch { }
try { theClient.Close(); }
catch { }
fileName = Path.GetFileName(tbFile.Text);
JODI = cmbProtocol.SelectedIndex == 0 ? true : false;
bwTransmit.RunWorkerAsync(theFile);
}
else { tbIP.Focus(); tbIP.SelectAll(); }
this.Invoke(EnableButtons);
StatusUpdate(string.Empty);
}
else
{
if (File.Exists(tbFile.Text))
{
if (IpAdress.IsMatch(tbIP.Text))
{
if (tbFile.Text.EndsWith(".wad") && cmbProtocol.SelectedIndex != 2)
{
if (directStart)
{ cmbProtocol.SelectedIndex = 2; }
else
{ ErrorBox("WAD files can only be sent to USB Loader GX!"); return; }
}
else if (!tbFile.Text.EndsWith(".wad") && cmbProtocol.SelectedIndex == 2)
{
if (directStart)
{ cmbProtocol.SelectedIndex = 0; }
else
{ ErrorBox("The USB Loader GX only accepts WAD files!"); return; }
}
Aborted = false;
btnSend.Text = "Abort";
btnBrowseFile.Enabled = false;
IsRunning = true;
FileStream fs = new FileStream(tbFile.Text, FileMode.Open);
byte[] theFile = new byte[fs.Length];
fs.Read(theFile, 0, theFile.Length);
fs.Close();
fileName = Path.GetFileName(tbFile.Text);
JODI = cmbProtocol.SelectedIndex == 0 ? true : false;
bwTransmit.RunWorkerAsync(theFile);
}
else { tbIP.Focus(); tbIP.SelectAll(); }
}
else { tbFile.Focus(); tbFile.SelectAll(); }
}
else { tbFile.Focus(); tbFile.SelectAll(); }
}
void bwTransmit_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
@ -287,10 +241,13 @@ namespace TransmitMii
{
byte[] theFile = e.Argument as byte[];
if (Transmit(fileName, theFile, JODI))
if (Transmit_Compress(fileName, theFile, JODI, File.Exists(Application.StartupPath + "\\zlib1.dll")))
{
MessageBox.Show("File Sent...", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
if (usedCompression)
MessageBox.Show(string.Format("Transmitted {0} kB in {1} milliseconds...\nCompression Ratio: {2}%", transmittedLength, timeElapsed, compressionRatio), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show(string.Format("Transmitted {0} kB in {1} milliseconds...", transmittedLength, timeElapsed), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void tbFile_MouseEnter(object sender, EventArgs e)
@ -329,6 +286,18 @@ namespace TransmitMii
lbStatus.Text = "Status:";
}
private void llbLinkExtension_MouseEnter(object sender, EventArgs e)
{
if (IsRunning == false)
lbStatus.Text = "Link extensions with TransmitMii...";
}
private void llbLinkExtension_MouseLeave(object sender, EventArgs e)
{
if (IsRunning == false)
lbStatus.Text = "Status:";
}
private void TransmitMii_Main_FormClosing(object sender, FormClosingEventArgs e)
{
bwTransmit.CancelAsync();
@ -357,5 +326,71 @@ namespace TransmitMii
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
tbFile.Text = files[0];
}
private void llbLinkExtension_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
ContextMenuStrip cmMenu = new ContextMenuStrip();
ToolStripMenuItem cmDol = new ToolStripMenuItem("DOL");
cmDol.Name = "cmDol";
cmDol.Click +=new EventHandler(cmMenu_Click);
if (TransmitMii_Associations.CheckAssociation(TransmitMii_Associations.Extension.DOL)) cmDol.Checked = true;
ToolStripMenuItem cmElf = new ToolStripMenuItem("ELF");
cmElf.Name = "cmElf";
cmElf.Click += new EventHandler(cmMenu_Click);
if (TransmitMii_Associations.CheckAssociation(TransmitMii_Associations.Extension.ELF)) cmElf.Checked = true;
ToolStripMenuItem cmWad = new ToolStripMenuItem("WAD");
cmWad.Name = "cmWad";
cmWad.Click += new EventHandler(cmMenu_Click);
if (TransmitMii_Associations.CheckAssociation(TransmitMii_Associations.Extension.WAD)) cmWad.Checked = true;
cmMenu.Items.Add(cmDol);
cmMenu.Items.Add(cmElf);
cmMenu.Items.Add(cmWad);
cmMenu.Show(MousePosition);
}
private void cmMenu_Click(object sender, EventArgs e)
{
try
{
ToolStripMenuItem cmSender = sender as ToolStripMenuItem;
TransmitMii_Associations.Extension thisExt;
//CopyIcon();
switch (cmSender.Name)
{
case "cmElf":
thisExt = TransmitMii_Associations.Extension.ELF;
break;
case "cmWad":
thisExt = TransmitMii_Associations.Extension.WAD;
break;
default:
thisExt = TransmitMii_Associations.Extension.DOL;
break;
}
if (cmSender.Checked == false)
{
if (TransmitMii_Associations.AddAssociation(thisExt, true, Application.ExecutablePath, false))
MessageBox.Show("Extension linked!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
ErrorBox("An error occured!");
}
else
{
if (TransmitMii_Associations.DeleteAssociation(thisExt))
MessageBox.Show("Extension unlinked!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
ErrorBox("An error occured!");
}
}
catch (Exception ex) { ErrorBox(ex.Message); }
}
}
}

View File

@ -0,0 +1,267 @@
/* This file is part of TransmitMii
* Copyright (C) 2009 Leathl
*
* TransmitMii is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TransmitMii is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Net.Sockets;
namespace TransmitMii
{
partial class TransmitMii_Main
{
TcpClient theClient;
NetworkStream theStream;
System.Diagnostics.Stopwatch stopper = new System.Diagnostics.Stopwatch();
private double transmittedLength;
private int timeElapsed;
private bool usedCompression;
private double compressionRatio;
private bool Transmit_Compress(string fileName, byte[] fileData, bool JODI, bool compress)
{
stopper.Reset(); stopper.Start();
if (!Environment.OSVersion.ToString().Contains("Windows"))
compress = false;
theClient = new TcpClient();
byte[] compFileData;
int Blocksize = 4 * 1024;
if (!JODI) Blocksize = 16 * 1024;
byte[] buffer = new byte[4];
string theIP = tbIP.Text;
StatusUpdate("Connecting...");
try { theClient.Connect(theIP, 4299); }
catch (Exception ex) { if (!Aborted) ErrorBox("Connection Failed:\n" + ex.Message); theClient.Close(); return false; }
theStream = theClient.GetStream();
StatusUpdate("Connected... Sending Magic...");
buffer[0] = (byte)'H';
buffer[1] = (byte)'A';
buffer[2] = (byte)'X';
buffer[3] = (byte)'X';
try { theStream.Write(buffer, 0, 4); }
catch (Exception ex) { if (!Aborted) ErrorBox("Error sending Magic:\n" + ex.Message); theStream.Close(); theClient.Close(); return false; }
StatusUpdate("Magic Sent... Sending Version Info...");
if (JODI)
{
buffer[0] = 0;
buffer[1] = 5;
buffer[2] = (byte)(((fileName.Length + 2) >> 8) & 0xff);
buffer[3] = (byte)((fileName.Length + 2) & 0xff);
}
else
{
buffer[0] = 0;
buffer[1] = 1;
buffer[2] = 0;
buffer[3] = 0;
}
try { theStream.Write(buffer, 0, 4); }
catch (Exception ex) { if (!Aborted) ErrorBox("Error sending Version Info:\n" + ex.Message); theStream.Close(); theClient.Close(); return false; }
if (JODI && compress)
{
StatusUpdate("Version Info Sent... Compressing File...");
try { compFileData = zlib.Compress(fileData); }
catch
{
//Compression failed, let's continue without compression
if (!Aborted) ErrorBox("a");
compFileData = fileData;
fileData = new byte[0];
}
StatusUpdate("Compressed File... Sending Filesize...");
}
else
{
compFileData = fileData;
fileData = new byte[0];
StatusUpdate("Version Info Sent... Sending Filesize...");
}
//First compressed filesize, then uncompressed filesize
buffer[0] = (byte)((compFileData.Length >> 24) & 0xff);
buffer[1] = (byte)((compFileData.Length >> 16) & 0xff);
buffer[2] = (byte)((compFileData.Length >> 8) & 0xff);
buffer[3] = (byte)(compFileData.Length & 0xff);
try { theStream.Write(buffer, 0, 4); }
catch (Exception ex) { if (!Aborted) ErrorBox("Error sending Filesize:\n" + ex.Message); theStream.Close(); theClient.Close(); return false; }
if (JODI)
{
buffer[0] = (byte)((fileData.Length >> 24) & 0xff);
buffer[1] = (byte)((fileData.Length >> 16) & 0xff);
buffer[2] = (byte)((fileData.Length >> 8) & 0xff);
buffer[3] = (byte)(fileData.Length & 0xff);
try { theStream.Write(buffer, 0, 4); }
catch (Exception ex) { if (!Aborted) ErrorBox("Error sending Filesize:\n" + ex.Message); theStream.Close(); theClient.Close(); return false; }
}
StatusUpdate("Filesize Sent... Sending File...");
int off = 0;
int cur = 0;
int count = compFileData.Length / Blocksize;
int left = compFileData.Length % Blocksize;
try
{
do
{
StatusUpdate("Sending File: " + ((cur + 1) * 100 / count).ToString() + "%");
theStream.Write(compFileData, off, Blocksize);
off += Blocksize;
cur++;
} while (cur < count);
if (left > 0)
{
theStream.Write(compFileData, off, compFileData.Length - off);
}
}
catch (Exception ex) { if (!Aborted) ErrorBox("Error sending File:\n" + ex.Message); theStream.Close(); theClient.Close(); return false; }
if (JODI)
{
StatusUpdate("File Sent... Sending Arguments...");
byte[] theArgs = new byte[fileName.Length + 2];
for (int i = 0; i < fileName.Length; i++) { theArgs[i] = (byte)fileName.ToCharArray()[i]; }
try { theStream.Write(theArgs, 0, theArgs.Length); }
catch (Exception ex) { if (!Aborted) ErrorBox("Error sending Arguments:\n" + ex.Message); theStream.Close(); theClient.Close(); return false; }
}
theStream.Close();
theClient.Close();
StatusUpdate(string.Empty);
stopper.Stop();
this.timeElapsed = (int)stopper.ElapsedMilliseconds;
this.usedCompression = compress;
this.transmittedLength = Math.Round(compFileData.Length * 0.0009765625, 2);
if (compress && fileData.Length != 0)
this.compressionRatio = (compFileData.Length * 100) / fileData.Length;
return true;
}
//private bool Transmit(string fileName, byte[] fileData, bool JODI)
//{
// TcpClient theClient = new TcpClient();
// NetworkStream theStream;
// int Blocksize = 4 * 1024;
// if (!JODI) Blocksize = 16 * 1024;
// byte[] buffer = new byte[4];
// string theIP = tbIP.Text;
// StatusUpdate("Connecting...");
// try { theClient.Connect(theIP, 4299); }
// catch (Exception ex) { if (!Aborted) ErrorBox("Connection Failed:\n" + ex.Message); theClient.Close(); return false; }
// theStream = theClient.GetStream();
// StatusUpdate("Connected... Sending Magic...");
// buffer[0] = (byte)'H';
// buffer[1] = (byte)'A';
// buffer[2] = (byte)'X';
// buffer[3] = (byte)'X';
// try { theStream.Write(buffer, 0, 4); }
// catch (Exception ex) { if (!Aborted) ErrorBox("Error sending Magic:\n" + ex.Message); theStream.Close(); theClient.Close(); return false; }
// StatusUpdate("Magic Sent... Sending Version Info...");
// if (JODI)
// {
// buffer[0] = 0;
// buffer[1] = 5;
// buffer[2] = (byte)(((fileName.Length + 2) >> 8) & 0xff);
// buffer[3] = (byte)((fileName.Length + 2) & 0xff);
// }
// else
// {
// buffer[0] = 0;
// buffer[1] = 1;
// buffer[2] = 0;
// buffer[3] = 0;
// }
// try { theStream.Write(buffer, 0, 4); }
// catch (Exception ex) { if (!Aborted) ErrorBox("Error sending Version Info:\n" + ex.Message); theStream.Close(); theClient.Close(); return false; }
// StatusUpdate("Version Info Sent... Sending Filesize...");
// //First compressed filesize, then uncompressed filesize
// buffer[0] = (byte)((fileData.Length >> 24) & 0xff);
// buffer[1] = (byte)((fileData.Length >> 16) & 0xff);
// buffer[2] = (byte)((fileData.Length >> 8) & 0xff);
// buffer[3] = (byte)(fileData.Length & 0xff);
// try { theStream.Write(buffer, 0, 4); }
// catch (Exception ex) { if (!Aborted) ErrorBox("Error sending Filesize:\n" + ex.Message); theStream.Close(); theClient.Close(); return false; }
// if (JODI)
// {
// buffer[0] = 0;
// buffer[1] = 0;
// buffer[2] = 0;
// buffer[3] = 0;
// try { theStream.Write(buffer, 0, 4); }
// catch (Exception ex) { if (!Aborted) ErrorBox("Error sending Filesize:\n" + ex.Message); theStream.Close(); theClient.Close(); return false; }
// }
// StatusUpdate("Filesize Sent... Sending File...");
// int off = 0;
// int cur = 0;
// int count = fileData.Length / Blocksize;
// int left = fileData.Length % Blocksize;
// try
// {
// do
// {
// StatusUpdate("Sending File: " + ((cur + 1) * 100 / count).ToString() + "%");
// theStream.Write(fileData, off, Blocksize);
// off += Blocksize;
// cur++;
// } while (cur < count);
// if (left > 0)
// {
// theStream.Write(fileData, off, fileData.Length - off);
// }
// }
// catch (Exception ex) { if (!Aborted) ErrorBox("Error sending File:\n" + ex.Message); theStream.Close(); theClient.Close(); return false; }
// if (JODI)
// {
// StatusUpdate("File Sent... Sending Arguments...");
// byte[] theArgs = new byte[fileName.Length + 2];
// for (int i = 0; i < fileName.Length; i++) { theArgs[i] = (byte)fileName.ToCharArray()[i]; }
// try { theStream.Write(theArgs, 0, theArgs.Length); }
// catch (Exception ex) { if (!Aborted) ErrorBox("Error sending Arguments:\n" + ex.Message); theStream.Close(); theClient.Close(); return false; }
// }
// theStream.Close();
// theClient.Close();
// StatusUpdate(string.Empty);
// return true;
//}
}
}

View File

@ -0,0 +1,59 @@
/* This file is part of TransmitMii
* Copyright (C) 2009 Leathl
*
* TransmitMii is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TransmitMii is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace TransmitMii
{
public static class zlib
{
public enum ZLibError : int
{
Z_OK = 0,
Z_STREAM_END = 1,
Z_NEED_DICT = 2,
Z_ERRNO = (-1),
Z_STREAM_ERROR = (-2),
Z_DATA_ERROR = (-3),
Z_MEM_ERROR = (-4),
Z_BUF_ERROR = (-5),
Z_VERSION_ERROR = (-6)
}
[DllImport("zlib1.dll")]
public static extern ZLibError compress2(byte[] dest, ref int destLength, byte[] source, int sourceLength, int level);
public static byte[] Compress(byte[] inFile)
{
ZLibError err;
byte[] outFile = new byte[inFile.Length];
int outLength = -1;
err = compress2(outFile, ref outLength, inFile, inFile.Length, 6);
if (err == ZLibError.Z_OK && outLength > -1)
{
Array.Resize(ref outFile, outLength);
return outFile;
}
else
throw new Exception("An error occured while compressing! Code: " + err.ToString());
}
}
}

BIN
TransmitMii/zlib1.dll Normal file

Binary file not shown.