Skip to content
This repository has been archived by the owner on Apr 25, 2022. It is now read-only.

Commit

Permalink
Version 20:
Browse files Browse the repository at this point in the history
- (OFFICIAL BETA RELEASE)
- Fixed bugs with json patcher
- Finished adding all original requested mods to the modpack
- Added a ETA estimator to the downloading of mods
- Improved UI during patching procedure
  • Loading branch information
Willster419 committed Mar 6, 2017
1 parent 4d8ceba commit 3fe91c1
Show file tree
Hide file tree
Showing 23 changed files with 1,497 additions and 295 deletions.
150 changes: 144 additions & 6 deletions RelicModManager/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public partial class MainWindow : Form
private string modAudioFolder;//res_mods/versiondir/audioww
private string tempPath = Path.GetTempPath();//C:/users/userName/appdata/local/temp
private const int MBDivisor = 1048576;
private string managerVersion = "version 19.4.1";
private string managerVersion = "version 20";
private string tanksLocation;//sample: c:/games/World_of_Tanks
private SelectFeatures features = new SelectFeatures();
//queue for downloading mods
Expand Down Expand Up @@ -101,6 +101,8 @@ private enum InstallState
private string tanksVersion;//0.9.x.y
BackgroundWorker deleteworker;
BackgroundWorker copyworker;
List<double> timeRemainArray = new List<double>();
double actualTimeRemain = 0;

//The constructur for the application
public MainWindow()
Expand Down Expand Up @@ -240,6 +242,18 @@ void downloader_DownloadProgressChanged(object sender, DownloadProgressChangedEv
downloadProgress.Text = "Downloading " + currentModDownloading + " ("+ MBytesIn + " MB" + " of " + MBytesTotal + " MB)";
childProgressBar.Value = e.ProgressPercentage;
speedLabel.Text = string.Format("{0} MB/s", (e.BytesReceived / 1048576d / sw.Elapsed.TotalSeconds).ToString("0.00"));
double totalTimeToDownload = MBytesTotal / (e.BytesReceived / 1048576d / sw.Elapsed.TotalSeconds);
double timeRemain = totalTimeToDownload - sw.Elapsed.TotalSeconds;
timeRemainArray.Add(timeRemain);
if (timeRemainArray.Count == 10)
{
double timeAverageRemain = 0;
foreach (double d in timeRemainArray)
timeAverageRemain += d;
actualTimeRemain = timeAverageRemain / 10;
timeRemainArray.Clear();
}
speedLabel.Text = speedLabel.Text + " ETA: " + Math.Round(actualTimeRemain,0) + " sec";
if (MBytesIn == 0 && MBytesTotal == 0)
{
//this.downloadProgress.Text = "Complete!";
Expand Down Expand Up @@ -290,6 +304,8 @@ void downloader_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged);
downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(downloader_DownloadFileCompleted);
downloader.Proxy = null;
timeRemainArray.Clear();
actualTimeRemain = 0;
sw.Reset();
sw.Start();
downloader.DownloadFileAsync(downloadQueue[0].URL, downloadQueue[0].zipFile);
Expand Down Expand Up @@ -421,6 +437,7 @@ private void extractZipFilesUser()
private void patchFiles()
{
speedLabel.Text = "Patching...";
Application.DoEvents();
this.appendToLog("Starting to patch Relhax Mod Pack");
//don't do anything if the file does not exist
if (!Directory.Exists(tanksLocation + "\\_patch"))
Expand All @@ -437,7 +454,8 @@ private void patchFiles()
//the actual patch method
foreach (Patch p in patchList)
{
downloadProgress.Text = p.file;
downloadProgress.Text = "patching " + p.file;
Application.DoEvents();
if (p.type.Equals("regx"))
{
string temp = null;
Expand Down Expand Up @@ -858,7 +876,7 @@ private void MainWindow_Load(object sender, EventArgs e)
Application.DoEvents();
this.appendToLog("|------------------------------------------------------------------------------------------------|");
this.appendToLog("|RelHax ModManager " + managerVersion);
this.appendToLog("|Built on 03/03/2017, running at " + DateTime.Now);
this.appendToLog("|Built on 03/05/2017, running at " + DateTime.Now);
this.appendToLog("|Running on " + System.Environment.OSVersion.ToString());
this.appendToLog("|------------------------------------------------------------------------------------------------|");
//enforces a single instance of the program
Expand Down Expand Up @@ -1327,10 +1345,13 @@ private void RegxPatch(string fileLocation, string search, string replace, int l
else if (lineNumber == -1)
//search entire file and string and make one giant regex replacement
{
//but remove newlines first
file = Regex.Replace(file, "\n", "newline");
if (Regex.IsMatch(file,search))
{
file = Regex.Replace(file,search,replace);
}
file = Regex.Replace(file, "newline", "\n");
sb.Append(file);
}
else
Expand All @@ -1355,6 +1376,43 @@ private void RegxPatch(string fileLocation, string search, string replace, int l
//method to parse json files
public void jsonPatch(string jsonFile, string jsonPath, string newValue)
{
//try to convert the new value to an int or double first
bool newValueBool = false;
int newValueInt = -69420;
double newValueDouble = -69420.0d;
bool useBool = false;
bool useInt = false;
bool useDouble = false;
try
{
newValueBool = bool.Parse(newValue);
useBool = true;
useInt = false;
useDouble = false;
}
catch (FormatException)
{

}
try
{
newValueDouble = double.Parse(newValue);
useDouble = true;
}
catch (FormatException)
{

}
try
{
newValueInt = int.Parse(newValue);
useInt = true;
useDouble = false;
}
catch (FormatException)
{

}
//check if it's the new structure
if (Regex.IsMatch(jsonFile, "^\\\\\\\\res_mods"))
{
Expand All @@ -1381,15 +1439,94 @@ public void jsonPatch(string jsonFile, string jsonPath, string newValue)

//load file from disk...
string file = File.ReadAllText(jsonFile);
//save the "$" lines
List<StringSave> ssList = new List<StringSave>();
//patch any single line comments out of it
StringBuilder backTogether = new StringBuilder();
string[] removeComments = file.Split('\n');
for (int i = 0; i < removeComments.Count(); i++)
{
string temp = removeComments[i];
//replace tabs with spaces
temp = Regex.Replace(temp, "\t", " ");
//remove single comment lines
if (Regex.IsMatch(temp, @"^ *//.*"))
temp = Regex.Replace(temp, @"//.*", "");
//remove comments after values
if (Regex.IsMatch(temp, @" +\/\/.*$"))
{
temp = Regex.Replace(temp, @" *\/\/.*$","");
}
if (Regex.IsMatch(temp, @"\${"))
{
bool hadComma = false;
if (Regex.IsMatch(temp,","))
{
hadComma = true;
}
StringSave ss = new StringSave();
ss.name = temp.Split('"')[1];
ss.value = temp.Split('$')[1];
ssList.Add(ss);
temp = "\"" + ss.name + "\"" + ": -69420" ;
if (hadComma)
temp = temp + ",";
}
backTogether.Append(temp + "\n");
}
file = backTogether.ToString();
//remove any stuff that would cause it to fail...
//like newlines
file = Regex.Replace(file, "\n", "");
file = Regex.Replace(file, "\r", "");
//like block comments
file = Regex.Replace(file, @"/\*.*?\*/", "");
JToken root = JToken.Parse(file);
foreach (var value in root.SelectTokens(jsonPath).ToList())
{
if (value == root)
root = JToken.FromObject(newValue);
else
value.Replace(JToken.FromObject(newValue));
{
if (useBool)
{
value.Replace(JToken.FromObject(newValueBool));
}
else if (useInt)
{
value.Replace(JToken.FromObject(newValueInt));
}
else if (useDouble)
{
value.Replace(JToken.FromObject(newValueDouble));
}
else
{
value.Replace(JToken.FromObject(newValue));
}
}
}
StringBuilder rebuilder = new StringBuilder();
string[] putBackDollas = root.ToString().Split('\n');
for (int i = 0; i < putBackDollas.Count(); i++)
{
string temp = putBackDollas[i];
if (Regex.IsMatch(temp,"-69420"))
{
string name = temp.Split('"')[1];
for (int j = 0; j < ssList.Count; j++)
{
if (name.Equals(ssList[j].name))
{
temp = "\"" + ssList[j].name + "\"" + ": $" + ssList[j].value;
putBackDollas[i] = temp;
ssList.RemoveAt(j);
}
}
}
rebuilder.Append(putBackDollas[i] + "\n");
}
File.WriteAllText(jsonFile, root.ToString());
File.WriteAllText(jsonFile, rebuilder.ToString());
}
//parses a patch xml file into an xml patch instance in memory to be enqueued
private void createPatchList(string xmlFile)
Expand Down Expand Up @@ -1525,7 +1662,8 @@ private void parseInstallationPart1()
//add the global dependencies to the dependency list
foreach (Dependency d in list.globalDependencies)
{
dependencies.Add(d);
if (d.enabled)
dependencies.Add(d);
}
//if mod is enabled and checked, add it to list of mods to extract/install
//same for configs
Expand Down
30 changes: 25 additions & 5 deletions RelicModManager/ModSelectionList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,19 @@ private void addMod(Mod m, TabPage t, int panelCount)
if (!oldCRC.Equals(m.configs[i].crc))
{
if (m.configs[i].enabled) configControlDD.Items.Add(m.configs[i].name + "_updated");
if (m.configs[i].configChecked) configControlDD.SelectedIndex = i;
if (m.configs[i].configChecked) configControlDD.SelectedItem = m.configs[i].name + "_updated";
break;
}
}
else if (!(File.Exists(configDownloadPath1)) && (m.configs[i].crc != null) && (!m.configs[i].crc.Equals("")))
{
//mod/config zip file does not exist locally, but a crc for it does, implying that the file needs to be downloaded
if (m.configs[i].enabled) configControlDD.Items.Add(m.configs[i].name + "_updated");
if (m.configs[i].configChecked) configControlDD.SelectedIndex = i;
if (m.configs[i].configChecked) configControlDD.SelectedItem = m.configs[i].name + "_updated";
break;
}
if (m.configs[i].enabled) configControlDD.Items.Add(m.configs[i].name);
if (m.configs[i].configChecked) configControlDD.SelectedIndex = i;
if (m.configs[i].configChecked) configControlDD.SelectedItem = m.configs[i].name;
break;

case "multi":
Expand Down Expand Up @@ -318,7 +318,7 @@ private void addMod(Mod m, TabPage t, int panelCount)
dropDownSizeLabel.TabIndex = 0;
dropDownSizeLabel.Text = "Nothing Selected";
dropDownSizeLabel.Name = t.Name + "_" + m.name + "_size";
dropDownSizeLabel.Enabled = true;
dropDownSizeLabel.Enabled = false;
configPanel.Controls.Add(dropDownSizeLabel);
}
}
Expand Down Expand Up @@ -692,6 +692,13 @@ void modCheckBox_CheckedChanged(object sender, EventArgs e)
bool oneSelected = false;
foreach (Control c in innerPanel.Controls)
{
if (c is Label)
{
if (c.Name.Equals(catagoryName + "_" + modName + "_size"))
{
c.Enabled = true;
}
}
if (c is RadioButton)
{
RadioButton b = (RadioButton)c;
Expand Down Expand Up @@ -737,7 +744,20 @@ void modCheckBox_CheckedChanged(object sender, EventArgs e)
ComboBox cbox = (ComboBox)c;
//only select if the index is on nothing
if (cbox.SelectedIndex == -1)
cbox.SelectedIndex = 0;
cbox.SelectedIndex = 0;
}
}
}
}
else
{
foreach (Control c in innerPanel.Controls)
{
if (c is Label)
{
if (c.Name.Equals(catagoryName + "_" + modName + "_size"))
{
c.Enabled = false;
}
}
}
Expand Down
59 changes: 57 additions & 2 deletions RelicModManager/PatchTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,72 @@ private void RegxPatch(string fileLocation, string search, string replace, int l
//method to parse json files
public void jsonPatch(string jsonFile, string jsonPath, string newValue)
{
//try to convert the new value to an int or double first
int newValueInt = -69420;
double newValueDouble = -69420.0d;
bool useInt = false;
bool useDouble = false;
try
{
newValueDouble = double.Parse(newValue);
useDouble = true;
}
catch (FormatException)
{

}
try
{
newValueInt = int.Parse(newValue);
useInt = true;
useDouble = false;
}
catch (FormatException)
{

}
//check that the file exists
string fileLocationSave = Path.GetFileNameWithoutExtension(jsonFile) + "_patched" + Path.GetExtension(jsonFile);
string fileLocationSave = Path.GetDirectoryName(jsonFile) + "\\" + Path.GetFileNameWithoutExtension(jsonFile) + "_patched" + Path.GetExtension(jsonFile);
//load file from disk...
string file = File.ReadAllText(jsonFile);
//patch any single line comments out of it
StringBuilder backTogether = new StringBuilder();
string[] removeComments = file.Split('\n');
for (int i = 0; i < removeComments.Count(); i++)
{
string temp = removeComments[i];
if (Regex.IsMatch(temp, @"^ *//.*"))
temp = Regex.Replace(temp, @"//.*", "");
backTogether.Append(temp + "\n");
}
file = backTogether.ToString();
//remove any stuff that would cause it to fail...
//like newlines
file = Regex.Replace(file, "\n", "");
file = Regex.Replace(file, "\r", "");
//like block comments
file = Regex.Replace(file, @"/\*.*\*/", "");
//file.Trim();
JToken root = JToken.Parse(file);
foreach (var value in root.SelectTokens(jsonPath).ToList())
{
if (value == root)
root = JToken.FromObject(newValue);
else
value.Replace(JToken.FromObject(newValue));
{
if (useInt)
{
value.Replace(JToken.FromObject(newValueInt));
}
else if (useDouble)
{
value.Replace(JToken.FromObject(newValueDouble));
}
else
{
value.Replace(JToken.FromObject(newValue));
}
}
}
if (File.Exists(fileLocationSave))
File.Delete(fileLocationSave);
Expand Down
Loading

0 comments on commit 3fe91c1

Please sign in to comment.