Skip to content

Commit

Permalink
InfoFileProcessing
Browse files Browse the repository at this point in the history
  • Loading branch information
LIPtoH committed Mar 23, 2020
1 parent 99cf6d2 commit b45ed17
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 8 deletions.
102 changes: 99 additions & 3 deletions TS SE Tool/CustomClasses/SavefileInfoData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,110 @@ limitations under the License.
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace TS_SE_Tool
{
public class SavefileInfoData
{
FormMain MainForm = Application.OpenForms.OfType<FormMain>().Single();
private string SaveContainerNameless { get; set; } = "";
public string Name { get; set; } = "\"\"";
public uint Time { get; set; } = 0;
public uint FileTime { get; set; } = 0;
public short Version { get; set; } = 1;

public string SaveName { get; set; }
public int FileTime { get; set; }
public List<string> Dependencies { get; set; }

public string GetText()
{
string OutputText = "SiiNunit\r\n{\r\n";

OutputText += "save_container : " + SaveContainerNameless + " {\r\n";
OutputText += " name: " + Name + "\r\n";
OutputText += " time: " + Time.ToString() + "\r\n";
OutputText += " file_time: " + FileTime.ToString() + "\r\n";
OutputText += " version: " + Version.ToString() + "\r\n";
OutputText += " dependencies: " + Dependencies.Count.ToString() + "\r\n";

byte DepCount = 0;
foreach(string tDep in Dependencies)
{
OutputText += " dependencies[" + DepCount + "]: \"" + tDep + "\"\r\n";
DepCount++;
}

OutputText += "}\r\n\r\n}";

return OutputText;
}

public void WriteToStream (StreamWriter _streamWriter)
{
_streamWriter.Write(GetText());
}

public void PrepareInfo(string[] _InfoFileLines)
{
string[] chunkOfline;
List<string> SavefileDependencies = new List<string>();

for (int line = 0; line < _InfoFileLines.Length; line++)
{
if (_InfoFileLines[line].StartsWith("save_container :"))
{
chunkOfline = _InfoFileLines[line].Split(new char[] { ' ' });
SaveContainerNameless = chunkOfline[2];
continue;
}

if (_InfoFileLines[line].StartsWith(" name:"))
{
chunkOfline = _InfoFileLines[line].Split(new char[] { ' ' });
Name = chunkOfline[2];
continue;
}

if (_InfoFileLines[line].StartsWith(" time:"))
{
chunkOfline = _InfoFileLines[line].Split(new char[] { ' ' });
Time = uint.Parse(chunkOfline[2]);
continue;
}

if (_InfoFileLines[line].StartsWith(" file_time:"))
{
chunkOfline = _InfoFileLines[line].Split(new char[] { ' ' });
FileTime = uint.Parse(chunkOfline[2]);
continue;
}

if (_InfoFileLines[line].StartsWith(" version:"))
{
chunkOfline = _InfoFileLines[line].Split(new char[] { ' ' });
Version = short.Parse(chunkOfline[2]);
continue;
}

if (_InfoFileLines[line].StartsWith(" dependencies:"))
{
chunkOfline = _InfoFileLines[line].Split(new char[] { ' ' });
Dependencies = new List<string>();
Dependencies.Capacity = short.Parse(chunkOfline[2]);
continue;
}

if (_InfoFileLines[line].StartsWith(" dependencies["))
{
chunkOfline = _InfoFileLines[line].Split(new char[] { '"' });
Dependencies.Add(chunkOfline[1]);
continue;
}

if (_InfoFileLines[line].StartsWith("}"))
{
break;
}
}
}
}
}
4 changes: 2 additions & 2 deletions TS SE Tool/Forms/FormConvoyControlPositions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@ private void buttonSave_Click(object sender, EventArgs e)
double tDT = MainForm.DateTimeToUnixTimeStamp(DateTime.UtcNow.ToLocalTime());

SavefileInfoData infoData = new SavefileInfoData();
infoData.SaveName = entry.Value[0];//Save name
infoData.FileTime = Convert.ToInt32(Math.Floor(tDT));
infoData.Name = entry.Value[0];//Save name
infoData.FileTime = Convert.ToUInt32(Math.Floor(tDT));

//Write info file
MainForm.WriteInfoFile(infoSii, fp + "\\info.sii", infoData);
Expand Down
10 changes: 7 additions & 3 deletions TS SE Tool/MethodsReadWrite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,10 @@ private void LoadSaveFile()
//textBoxDynamic.Text += LastModifiedTimestamp.ToString();

CheckSaveInfoData();

SavefileInfoData InfoData = new SavefileInfoData();
InfoData.PrepareInfo(tempInfoFileInMemory);

}
}

Expand Down Expand Up @@ -2137,11 +2141,11 @@ public void WriteInfoFile(string[] _infoFile, string _filePath, SavefileInfoData

if (InMemLine.StartsWith(" name:"))
{
if(_infoData.SaveName != null)
if(_infoData.Name != null)
{
string t = _infoData.SaveName;
string t = _infoData.Name;

if (_infoData.SaveName.Contains(" ") || _infoData.SaveName.Length == 0)
if (_infoData.Name.Contains(" ") || _infoData.Name.Length == 0)
t = "\"" + t + "\"";

InMemLine = " name: " + t;
Expand Down

0 comments on commit b45ed17

Please sign in to comment.