Skip to content

Commit

Permalink
Adding ModGenerator's ability to auto-install the test spawn mod if i…
Browse files Browse the repository at this point in the history
…t isn't installed.
  • Loading branch information
jcorvinus committed Aug 3, 2015
1 parent bf9887c commit 3b44668
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 12 deletions.
28 changes: 25 additions & 3 deletions ModManagementLibrary/ModProfile.cs
Expand Up @@ -21,13 +21,15 @@ public class ModProfile
public Dictionary<string, string> SwapFiles;
public string EXEFile;
public string EXEData;
public List<string> DLLDataFiles;
public List<string> DLLFiles;
public string GameType;
public string Game;

public ModProfile(string modFilePath)
{
StreamReader modIniFile = File.OpenText(modFilePath);

DLLDataFiles = new List<string>();
DLLFiles = new List<string>();

while(!modIniFile.EndOfStream)
Expand All @@ -42,15 +44,16 @@ public ModProfile(string modFilePath)
else if (modSplit[0] == "Author") Author = modSplit[1];
else if (modSplit[0] == "EXEFile") EXEFile = modSplit[1];
else if (modSplit[0] == "EXEData") EXEData = modSplit[1];
else if (modSplit[0] == "Game") GameType = modSplit[1];
else if (modSplit[0] == "Game") Game = modSplit[1];
else if (modSplit[0] == "DLLFile") DLLFiles.Add(modSplit[1]);
else
{
bool found = false;
foreach (string dllFile in ModManagement.SADXSystemDLLFiles)
{
if (modSplit[0] == string.Concat(dllFile, "Data"))
{
DLLFiles.Add(modSplit[1]);
DLLDataFiles.Add(modSplit[1]);
found = true;
break;
}
Expand All @@ -64,6 +67,25 @@ public ModProfile(string modFilePath)
}
}
}

modIniFile.Close();
}

public void Save(string modFilePath)
{
FileStream fileStream = File.OpenWrite(modFilePath);
StreamWriter modIniFile = new StreamWriter(fileStream);

modIniFile.WriteLine("Name=" + Name);
if(Description.Length > 0) modIniFile.WriteLine("Description=" + Description);
if(Author.Length > 0) modIniFile.WriteLine("Author=" + Author);
if(EXEFile.Length > 0) modIniFile.WriteLine("EXEFile=" + EXEFile);
if(EXEData.Length > 0) modIniFile.WriteLine("EXEData=" + EXEData);
foreach (string DLLFile in DLLFiles) modIniFile.WriteLine("DLLFile=" + DLLFile);
foreach (string DLLData in DLLDataFiles) modIniFile.WriteLine("DLLData=" + DLLData);
if(Game.Length > 0) modIniFile.WriteLine("Game=" + Game);

modIniFile.Close();
}
}
}
52 changes: 44 additions & 8 deletions SADXLVL2/MainForm.cs
Expand Up @@ -1412,7 +1412,7 @@ private void SaveStage(bool autoCloseDialog, bool closeProgramOnFinish = false)
file.AddRange(item.GetBytes());

File.WriteAllBytes(setstr, file.ToArray());
changedFiles.Add(setstr);
changedFiles.Add("\\system\\SET" + LevelData.SETName + LevelData.SETChars[i] + ".bin");
}
}

Expand Down Expand Up @@ -1447,7 +1447,7 @@ private void SaveStage(bool autoCloseDialog, bool closeProgramOnFinish = false)
file.AddRange(item.GetBytes());

File.WriteAllBytes(camString, file.ToArray());
changedFiles.Add(camString);
changedFiles.Add("\\system\\" + "CAM" + LevelData.SETName + LevelData.SETChars[i] + ".bin");
}
}

Expand All @@ -1473,7 +1473,7 @@ private void SaveStage(bool autoCloseDialog, bool closeProgramOnFinish = false)
{
string splineOutput = Path.Combine(splineDirectory, string.Format("{0}.ini", i));
LevelData.LevelSplines[i].Save(splineOutput);
changedFiles.Add(splineOutput);
changedFiles.Add(ini.Paths + i.ToString() + ".ini");
}
}
}
Expand Down Expand Up @@ -2838,7 +2838,10 @@ private void CopyUpdatedModFiles()
// load the user's EXEData - we do have to get this and the user's DLLData files every time this is called, simply because
// they might have changed since last time.
string exeDataInipath = Path.GetFullPath(Settings.GamePath + string.Concat("\\mods\\", SAEditorCommon.EditorOptions.ProjectName, "\\exeData.ini"));
DataMapping modExeDataMapping = IniSerializer.Deserialize<DataMapping>(exeDataInipath);
DataMapping modExeDataMapping = IniSerializer.Deserialize<DataMapping>(exeDataInipath); //todo: how do we handle this if the file doesn't yet exist?

bool hasChangedModExeMapping = false;
bool hasChangedDLLMappings = false; // todo: this might need to be an array, one for each dllfile. Don't want to re-build any more than we have to

// load the user's DLLData files
bool[] writeDLLs = new bool[ModManagement.ModManagement.SADXSystemDLLFiles.Length]; for (int i = 0; i < writeDLLs.Length; i++) writeDLLs[i] = false;
Expand All @@ -2849,7 +2852,7 @@ private void CopyUpdatedModFiles()
ModManagement.ModManagement.SADXSystemDLLFiles[i], "Data.ini"));

if (File.Exists(modRelativePath)) modDLLDataMappings[i] = IniSerializer.Deserialize<ModManagement.DLLDataMapping>(modRelativePath);
else modDLLDataMappings[i] = null; // later on in the process we'll need to create these if they're empty.
else modDLLDataMappings[i] = null; // todo: later on in the process we'll need to create these if they're empty. (and if any of our files belong here)
}
#endregion

Expand All @@ -2875,6 +2878,7 @@ private void CopyUpdatedModFiles()
}
#endregion

#region Check Mod-folder ini files for file entry
// we're going to check to see if our modloader ini files contain entries for the files.
// the user is going to expect them to load, and if they aren't part of these files, they won't load, so we'll need to fix that before it happens.
if (fileDataSource == ModManagement.ModManagement.DataSource.EXEData)
Expand All @@ -2897,6 +2901,7 @@ private void CopyUpdatedModFiles()
foreach (KeyValuePair<string, SA_Tools.FileInfo> item in sonicExeDataMapping.Files.Where((a, i) => a.Value.Filename == file))
{
modExeDataMapping.Files.Add(item.Key, item.Value);
hasChangedModExeMapping = true;
}
}
}
Expand All @@ -2910,15 +2915,46 @@ private void CopyUpdatedModFiles()
if(item.Value.Filename == file)
{
dllOutput = ModManagement.ModManagement.SADXSystemDLLFiles[i];
// todo: you need to fix the relative/absolute path problems inside of split's DLL functionality before this can be fixed!

// todo: look through the dll file's data mapping to see if we need to add the file
// if we do need to add it, don't forget to make the data mapping as changed
}
}
}
}
#endregion

#region Copy File to Mod Folder
// check to see if the project folder's version of the file is newer than the mod folder's version. If they're the same date, then the file
// is unchanged and we don't need to copy it.
string projectFileLocation = string.Concat(EditorOptions.ProjectPath, "\\", file);
string modFileLocation = string.Concat(EditorOptions.GamePath, "\\mods\\", EditorOptions.ProjectName, "\\", file);

System.IO.FileInfo projectFileInfo = new System.IO.FileInfo(projectFileLocation);
System.IO.FileInfo modFileInfo = new System.IO.FileInfo(modFileLocation);

// TODO: check to see if the project folder's version of the file is newer than the mod folder's version. If they're the same date, then the file
// TODO: is unchanged and we don't need to copy it.
if(projectFileInfo.LastWriteTime != modFileInfo.LastWriteTime)
{
Directory.CreateDirectory(Path.GetDirectoryName(modFileLocation));
File.Copy(projectFileLocation, modFileLocation, true);
}
#endregion
}

string modIniFilePath = Settings.GamePath + string.Concat("\\mods\\", SAEditorCommon.EditorOptions.ProjectName, "\\") + "mod.ini";
ModManagement.ModProfile modProfile = new ModManagement.ModProfile(modIniFilePath);

if(hasChangedModExeMapping)
{
IniSerializer.Serialize(modExeDataMapping, exeDataInipath);
}

if (File.Exists(exeDataInipath))
{
modProfile.EXEData = "exeData.ini";
}

IniSerializer.Serialize(modProfile, modIniFilePath);
}

private void PlayTestLevel()
Expand Down
Binary file not shown.
4 changes: 4 additions & 0 deletions StructConverter/Config/SADX/TestSpawn/mod.ini
@@ -0,0 +1,4 @@
Name=TestSpawn
Author=X-Hax
Description=Used by SADXLVL2. Doesn't do anything on its own.
DLLFile=TestSpawn.dll
2 changes: 1 addition & 1 deletion StructConverter/ModBuilder.cs
Expand Up @@ -123,7 +123,7 @@ private void PickProject()

// Load mod info
ModManagement.ModProfile modProfile = new ModProfile(string.Concat(projectFolder, "\\mod.ini"));
gameType = ModManagement.ModManagement.GameFromString(modProfile.GameType); // todo: rectify this with MainForm_Load's game type checkboxes
gameType = ModManagement.ModManagement.GameFromString(modProfile.Game); // todo: rectify this with MainForm_Load's game type checkboxes

// add all the files from the DataMappings folder
string dataMappingsFolder = string.Concat(projectFolder, "\\DataMappings\\");
Expand Down
6 changes: 6 additions & 0 deletions StructConverter/ModGenerator.csproj
Expand Up @@ -78,6 +78,9 @@
<Compile Include="SplitSettings.Designer.cs">
<DependentUpon>SplitSettings.cs</DependentUpon>
</Compile>
<Content Include="Config\SADX\TestSpawn\TestSpawn.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
Expand Down Expand Up @@ -143,6 +146,9 @@
<Content Include="Config\SADX\objdefs.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Config\SADX\TestSpawn\mod.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
22 changes: 22 additions & 0 deletions StructConverter/NewProject.cs
Expand Up @@ -167,6 +167,28 @@ private void splitBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
}
#endregion

#region Install TestSpawn If Necessary
string testSpawnModsFolder = string.Concat(gamePathTextBox.Text, "\\mods\\TestSpawn\\");
string testSpawnConfigFolder = string.Concat(Application.StartupPath, "\\Config\\SADX\\TestSpawn\\");
if (!Directory.Exists(testSpawnModsFolder)) Directory.CreateDirectory(testSpawnModsFolder);

string[] testSpawnFiles = Directory.GetFiles(testSpawnConfigFolder);

foreach(string file in testSpawnFiles)
{
// check to see if the file exists in the install directory, if not, move it from the local config folder.
string destinationFile = string.Concat(testSpawnModsFolder, Path.GetFileName(file));
FileInfo sourceFileHandle = new FileInfo(file);
FileInfo destinationFileInfo = new FileInfo(destinationFile);

if (!File.Exists(destinationFile) ||
((sourceFileHandle.Length != destinationFileInfo.Length) || (sourceFileHandle.CreationTime != destinationFileInfo.CreationTime)))
{
File.Copy(string.Concat(file), destinationFile, true);
}
}
#endregion

#region Emulating old SplitAll.bat
// splitSADX.bat
string[] args = new string[3];
Expand Down

0 comments on commit 3b44668

Please sign in to comment.