-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate descriptor.mod and startup arguments
I finally added a way to generate descriptor.mod files into Documents\Paradox Interactive\Hearts of Iron IV\mod and also added start up arguments, both of these options are in Settings tab. Please make sure you have the mod folder created in documents because otherwise the program will crash and burn and it's to late for me to fix it I just want to sleep. Keep in mind that these features are barely tested so please if you encounter any problems just open up an issue. - Added ability to update mods by creating descriptor.mod files (Requested by: #4 ) - Added startup arguments (Requseted by: #5 )
- Loading branch information
Showing
12 changed files
with
395 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,133 @@ | ||
using System; | ||
using Hoi4_Launcher.Utility; | ||
using SharpCompress.Readers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.IO.Compression; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace Hoi4_Launcher.Parser | ||
{ | ||
class modParser | ||
{ | ||
public string modsFolder; | ||
public string[] mods; | ||
public bool isPathValid = false; | ||
public Exception exception; | ||
public modParser(string thisPath) | ||
{ | ||
this.modsFolder = workshop(thisPath); | ||
try | ||
{ | ||
mods = Directory.GetDirectories(modsFolder); | ||
this.isPathValid = true; | ||
} | ||
catch (Exception ex) { | ||
string message = "I couldn't find the path to the mods directory." + | ||
Environment.NewLine+ | ||
"Perhaps this is not a steam install?" + | ||
Environment.NewLine + | ||
"Either way descriptor.mod is disabled. If you think this is an issue, open one on github."+ | ||
Environment.NewLine + | ||
"More info in Log tab!"; | ||
string title = "Something intresting happened"; | ||
MessageBox.Show(message, title); | ||
Properties.Settings.Default.generateDescriptor = false; | ||
Properties.Settings.Default.Save(); | ||
this.exception = ex; | ||
} | ||
} | ||
public string workshop(string path) => path.Split(new string[] { "steamapps" }, StringSplitOptions.None)[0] + "steamapps\\workshop\\content\\394360"; | ||
|
||
public bool createDescriptorFile(string path, string savePath, string id) | ||
{ | ||
DirectoryInfo dInfo = new DirectoryInfo(path); | ||
FileInfo zipFile; | ||
try | ||
{ | ||
zipFile = dInfo.GetFilesByExtensions(new string[] { ".rar", ".zip", ".7z" }).First(); | ||
} | ||
catch (Exception ex) { | ||
zipFile = null; | ||
} | ||
// We are going to check if descriptor.mod exists | ||
if (File.Exists(dInfo.FullName + "\\descriptor.mod")) | ||
{ | ||
if (!File.Exists(savePath + "\\ugc_" + id + ".mod")){ | ||
var descriptorFile = editDescriptor(File.ReadAllText(dInfo.FullName + "\\descriptor.mod"), dInfo.FullName); | ||
System.IO.File.WriteAllLines(savePath + "\\ugc_" + id + ".mod", descriptorFile); | ||
} | ||
return true; | ||
} | ||
else if (zipFile != null) | ||
{ | ||
if (!File.Exists(savePath + "\\ugc_" + id + ".mod")) | ||
{ | ||
try | ||
{ | ||
//using (ZipArchive archive = ZipFile.OpenRead(zipFile.FullName)) | ||
//{ | ||
// ZipArchiveEntry descriptor = archive.GetEntry("descriptor.mod"); | ||
// descriptor.ExtractToFile(@"descriptor.mod"); | ||
// var textStream = descriptor.Open(); | ||
// StreamReader reader = new StreamReader(textStream); | ||
// var descriptorFile = editDescriptor(reader.ReadToEnd(), zipFile.FullName); | ||
// System.IO.File.WriteAllLines(savePath + "\\ugc_" + id + ".mod", descriptorFile); | ||
//} | ||
|
||
using (Stream stream = File.OpenRead(zipFile.FullName)) | ||
using (var reader = ReaderFactory.Open(stream)) | ||
{ | ||
while (reader.MoveToNextEntry()) | ||
{ | ||
if (!reader.Entry.IsDirectory && reader.Entry.Key == "descriptor.mod") | ||
{ | ||
reader.WriteEntryToFile(@"tempDescriptor.mod"); | ||
var descriptorFile = editDescriptor(File.ReadAllText(@"tempDescriptor.mod"), zipFile.FullName); | ||
System.IO.File.WriteAllLines(savePath + "\\ugc_" + id + ".mod", descriptorFile); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
catch (Exception ex) { } | ||
} | ||
if (File.Exists(@"tempDescriptor.mod")) | ||
{ | ||
File.Delete(@"tempDescriptor.mod"); | ||
} | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
// this rlly needs a rewrite | ||
private string[] editDescriptor(string descriptor, string path) | ||
{ | ||
bool doesItContainPath = false; | ||
List<string> descriptorFile = new List<string>(); | ||
foreach (var line in descriptor.Split(new string[] { Environment.NewLine, "\n\t", "\n\r", "\n"}, StringSplitOptions.RemoveEmptyEntries)) | ||
{ | ||
var currentLine = line; | ||
if (line.Split('=').First().ToLower() == "path") | ||
{ | ||
currentLine = "path=" + path; | ||
doesItContainPath = true; | ||
|
||
} | ||
descriptorFile.Add(currentLine); | ||
} | ||
if (!doesItContainPath) | ||
{ | ||
descriptorFile.Add("path=" + path); | ||
} | ||
return descriptorFile.ToArray(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
<?xml version='1.0' encoding='utf-8'?> | ||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)"> | ||
<Profiles> | ||
<Profile Name="(Default)" /> | ||
</Profiles> | ||
<Settings /> | ||
</SettingsFile> | ||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Hoi4_Launcher.Properties" GeneratedClassName="Settings"> | ||
<Profiles /> | ||
<Settings> | ||
<Setting Name="generateDescriptor" Type="System.Boolean" Scope="User"> | ||
<Value Profile="(Default)">False</Value> | ||
</Setting> | ||
<Setting Name="startArguments" Type="System.String" Scope="User"> | ||
<Value Profile="(Default)" /> | ||
</Setting> | ||
</Settings> | ||
</SettingsFile> |
Oops, something went wrong.