GameLauncher/PSLauncher/ClientINI.cs

54 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace PSLauncher
{
class ClientINI
{
string inipath;
public ClientINI(String inipath)
{
this.inipath = inipath;
}
public void writeEntries(List<ServerEntry> entries, int primaryIndex=0)
{
FileStream writer = File.Open(this.inipath, FileMode.Create);
// reorder based on primary index
if(primaryIndex != 0)
{
entries.Insert(0, entries[primaryIndex]);
entries.RemoveAt(primaryIndex + 1);
}
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fvi.FileVersion;
string contents = "# FILE AUTOGENERATED BY PSForever Launcher " + version + "\n";
contents += "[network]\n";
for(int i = 0; i < entries.Count; i++)
{
ServerEntry entry = entries[i];
contents += "# Name: " + entry.name + "\n";
// we only want login0 to be used, but have the rest written there for manual editing as well
contents += String.Format("{3}login{0}={1}:{2}\n", i, entry.hostname, entry.port,
i == 0 ? "" : "#");
}
byte[] outBytes = Encoding.ASCII.GetBytes(contents);
writer.Write(outBytes, 0, outBytes.Length);
writer.Close();
}
}
}