Skip to content

Commit

Permalink
Creates a log file.
Browse files Browse the repository at this point in the history
By default it creates a log file (both in CMD mode and in GUI mode) with the messages of the injection process of the command line.
  • Loading branch information
phacoxcll authored Jul 11, 2019
1 parent ef9a481 commit e6b0ca1
Show file tree
Hide file tree
Showing 7 changed files with 277 additions and 240 deletions.
2 changes: 1 addition & 1 deletion 64Inject/64Inject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,6 @@
</Target>
-->
<PropertyGroup>
<PreBuildEvent>"C:\Users\Alberto\Documents\Visual Studio 2008\Projects\64Inject\64Inject\CllAssemblyVersion.exe" assemblyInfo "$(ProjectDir)Properties\AssemblyInfo.cs" projectPath "$(ProjectPath)" config "$(ConfigurationName)" platform "$(PlatformName)" title "$(SolutionName)" format "major.minor.build.revision" replaceIn "$(ProjectDir)64Injector.cs"</PreBuildEvent>
<PreBuildEvent>"C:\Users\Alberto\source\repos\64Inject\64Inject\CllAssemblyVersion.exe" assemblyInfo "$(ProjectDir)Properties\AssemblyInfo.cs" projectPath "$(ProjectPath)" config "$(ConfigurationName)" platform "$(PlatformName)" title "$(SolutionName)" format "major.minor.build.revision" replaceIn "$(ProjectDir)64Injector.cs"</PreBuildEvent>
</PropertyGroup>
</Project>
323 changes: 164 additions & 159 deletions 64Inject/64InjectCMD.cs

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions 64Inject/64InjectGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public partial class _64InjectGUI : Form

public _64InjectGUI()
{
Cll.Log.SaveIn("64Inject_log.txt");
Cll.Log.WriteLine(DateTime.UtcNow.ToString());
Cll.Log.WriteLine("64Inject open in GUI mode.");

injector = new _64Injector();

InitializeComponent();
Expand Down Expand Up @@ -100,6 +104,8 @@ public _64InjectGUI()
private void _64InjectGUI_FormClosing(object sender, FormClosingEventArgs e)
{
SaveXmlConfig();
Cll.Log.WriteLine("Close.");
Cll.Log.WriteLine("----------------------------------------------------------------");
}

#region Config
Expand Down Expand Up @@ -660,6 +666,20 @@ private void buttonInject_Click(object sender, EventArgs e)

if (_continue)
{
Cll.Log.WriteLine("Injecting - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
if (injector.BasePath != null) Cll.Log.WriteLine("base: " + injector.BasePath);
if (injector.ShortName != null) Cll.Log.WriteLine("name: " + injector.ShortName);
if (injector.LongName != null) Cll.Log.WriteLine("longname:\n" + injector.LongName);
if (injector.InPath != null) Cll.Log.WriteLine("in: " + injector.InPath);
if (injector.RomPath != null) Cll.Log.WriteLine("rom: " + injector.RomPath);
if (injector.IniPath != null) Cll.Log.WriteLine("ini: " + injector.IniPath);
if (injector.BootTvPath != null) Cll.Log.WriteLine("tv: " + injector.BootTvPath);
if (injector.BootDrcPath != null) Cll.Log.WriteLine("drc: " + injector.BootDrcPath);
if (injector.IconPath != null) Cll.Log.WriteLine("icon: " + injector.IconPath);
if (injector.OutPath != null) Cll.Log.WriteLine("out: " + injector.OutPath);
Cll.Log.WriteLine("encrypt: " + injector.Encrypt.ToString());
Cll.Log.WriteLine("Please wait...");

if (injector.Inject())
MessageBox.Show("Injection completed successfully!",
"64Inject", MessageBoxButtons.OK, MessageBoxIcon.Information);
Expand Down Expand Up @@ -839,10 +859,12 @@ private bool AskBase()

textBoxBaseFrom.Text = folderBrowserDialog.SelectedPath;

Cll.Log.WriteLine("Loading base.");
if (injector.LoadBase(textBoxBaseFrom.Text))
{
labelLoadedBase.Text = "Base loaded: " + injector.LoadedBase;
panelLoadedBase.BackgroundImage = global::_64Inject.Properties.Resources.checkmark_16;
Cll.Log.WriteLine("Base loaded: " + injector.LoadedBase);
return true;
}
else
Expand Down
79 changes: 59 additions & 20 deletions 64Inject/64Injector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ namespace _64Inject
{
public class _64Injector
{
public const string Release = "1.2 debug"; //CllVersionReplace "major.minor stability"

public Cll.Log Log;
public const string Release = "1.3 debug"; //CllVersionReplace "major.minor stability"

public string BasePath;
public string ShortName;
Expand All @@ -35,8 +33,7 @@ public class _64Injector
public float Scale;
public BootImage BootTvImg;
public BootImage BootDrcImg;
public IconImage IconImg;

public IconImage IconImg;

public bool BaseIsLoaded
{
Expand Down Expand Up @@ -125,8 +122,6 @@ public string TitleId

public _64Injector()
{
Log = new Cll.Log();

BasePath = null;
ShortName = null;
LongName = null;
Expand Down Expand Up @@ -155,7 +150,7 @@ public bool Inject()
{
_base = GetLoadedBase();
bool _continue = BaseIsLoaded;
Log.WriteLine("The base is ready: " + _continue.ToString());
Cll.Log.WriteLine("The base is ready: " + _continue.ToString());

if (_continue)
_continue = InjectGameLayout();
Expand All @@ -173,21 +168,21 @@ public bool Inject()
{
if (Encrypt)
{
Log.WriteLine("Creating encrypted output.");
Cll.Log.WriteLine("Creating encrypted output.");
string inPath = Environment.CurrentDirectory + "\\base";
_continue = NusContent.Encrypt(inPath, OutPath);
}
else
{
Log.WriteLine("Creating unencrypted output.");
Cll.Log.WriteLine("Creating unencrypted output.");
_continue = Useful.DirectoryCopy("base", OutPath, true);
}
}

if (_continue)
Log.WriteLine("Injection completed successfully!");
Cll.Log.WriteLine("Injection completed successfully!");
else
Log.WriteLine("The injection failed.");
Cll.Log.WriteLine("The injection failed.");

return _continue;
}
Expand All @@ -197,6 +192,8 @@ private bool InjectGameLayout()
FileStream fs = null;
try
{
Cll.Log.WriteLine("Editing \"FrameLayout.arc\" file.");

byte darkFilterB = (byte)(DarkFilter ? 1 : 0);
byte[] widescreenB = Widescreen ?
new byte[] { 0x44, 0xF0, 0, 0 } :
Expand Down Expand Up @@ -290,6 +287,7 @@ private bool InjectGameLayout()
}
else if (name == "power_save_bg")
{
Cll.Log.WriteLine("\"FrameLayout.arc\" file editing successfully.");
return true;
}

Expand All @@ -309,7 +307,7 @@ private bool InjectGameLayout()
}
fs.Close();
}
catch { Log.WriteLine("Error editing the \"FrameLayout.arc\"."); }
catch { Cll.Log.WriteLine("Error editing \"FrameLayout.arc\"."); }
finally { if (fs != null) fs.Close(); }

return false;
Expand All @@ -326,6 +324,8 @@ private bool InjectImages()

try
{
Cll.Log.WriteLine("Creating bitmaps.");

if (BootTvPath != null)
tmp = new Bitmap(BootTvPath);
else
Expand Down Expand Up @@ -355,19 +355,32 @@ private bool InjectImages()
g.DrawImage(tmp, new Rectangle(0, 0, 128, 128));
g.Dispose();
tmp.Dispose();

Cll.Log.WriteLine("Bitmaps created.");
}
catch
{
Log.WriteLine("Error creating images.");
Cll.Log.WriteLine("Error creating bitmaps.");
return false;
}

if (!NusContent.ConvertToTGA(bootTvImg, currentDir + "\\base\\meta\\bootTvTex.tga"))
{
Cll.Log.WriteLine("Error creating \"bootTvTex.tga\" file.");
return false;
}
if (!NusContent.ConvertToTGA(bootDrcImg, currentDir + "\\base\\meta\\bootDrcTex.tga"))
{
Cll.Log.WriteLine("Error creating \"bootDrcTex.tga\" file.");
return false;
}
if (!NusContent.ConvertToTGA(iconImg, currentDir + "\\base\\meta\\iconTex.tga"))
{
Cll.Log.WriteLine("Error creating \"iconTex.tga\" file.");
return false;
}

Cll.Log.WriteLine("Injected TGA files.");

return true;
}
Expand All @@ -391,6 +404,8 @@ private bool InjectMeta()

try
{
Cll.Log.WriteLine("Editing \"app.xml\" and \"meta.xml\" files.");

xmlApp.Load("base\\code\\app.xml");
xmlMeta.Load("base\\meta\\meta.xml");

Expand Down Expand Up @@ -421,11 +436,13 @@ private bool InjectMeta()
app.Close();
meta.Close();

Cll.Log.WriteLine("\"app.xml\" and \"meta.xml\" files editing successfully.");

return true;
}
catch
{
Log.WriteLine("Error editing the \"meta.xml\".");
Cll.Log.WriteLine("Error editing \"app.xml\" and \"meta.xml\" files.");
}

return false;
Expand All @@ -437,27 +454,42 @@ private bool InjectRom()

try
{
Cll.Log.WriteLine("Empty \"base\\content\\config\" folder.");
Directory.Delete("base\\content\\config", true);
Directory.CreateDirectory("base\\content\\config");

Cll.Log.WriteLine("Injecting INI data.");
if (IniIsLoaded)
{
FileStream fs = File.Open("base\\content\\config\\U" + Rom.ProductCodeVersion + ".z64.ini", FileMode.Create);
fs.Write(_ini, 0, _ini.Length);
fs.Close();
Cll.Log.WriteLine("INI injected.");
}
else
{
File.Create("base\\content\\config\\U" + Rom.ProductCodeVersion + ".z64.ini").Close();
Cll.Log.WriteLine("An empty INI injected.");
}

Cll.Log.WriteLine("Empty \"base\\content\\rom\" folder.");
Directory.Delete("base\\content\\rom", true);
Directory.CreateDirectory("base\\content\\rom");

if (!RomN64.ToBigEndian(RomPath, "base\\content\\rom\\U" + Rom.ProductCodeVersion + ".z64"))
Cll.Log.WriteLine("Injecting ROM.");
if (RomN64.ToBigEndian(RomPath, "base\\content\\rom\\U" + Rom.ProductCodeVersion + ".z64"))
{
Cll.Log.WriteLine("Injected ROM.");
}
else
{
Cll.Log.WriteLine("ROM not injected, \"ToBigEndian\" failed.");
injected = false;
}
}
catch
{
Log.WriteLine("Error injecting ROM.");
Cll.Log.WriteLine("Error injecting ROM.");
injected = false;
}

Expand All @@ -470,16 +502,23 @@ private bool InjectRom()
public bool LoadBase(string path)
{
if (Directory.Exists("base"))
{
Directory.Delete("base", true);
Cll.Log.WriteLine("Previous base deleted.");
}

if (IsValidBase(path))
{
Cll.Log.WriteLine("The \"" + path + "\" folder contains a valid base.");
Useful.DirectoryCopy(path, "base", true);

}
else if (IsValidEncryptedBase(path))
{
Cll.Log.WriteLine("The \"" + path + "\" folder contains a valid encrypted base.");
NusContent.Decrypt(path, "base");

}
else
Console.WriteLine("The \"" + path + "\" folder not contain a valid base.");
Cll.Log.WriteLine("The \"" + path + "\" folder not contains a valid base.");

_base = GetLoadedBase();

Expand Down
Loading

0 comments on commit e6b0ca1

Please sign in to comment.