mirror of
https://github.com/psforever/GameLauncher.git
synced 2026-01-20 02:34:45 +00:00
54 lines
1.7 KiB
C#
54 lines
1.7 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 + Environment.NewLine;
|
|
contents += "[network]" + Environment.NewLine;
|
|
|
|
for(int i = 0; i < entries.Count; i++)
|
|
{
|
|
ServerEntry entry = entries[i];
|
|
|
|
contents += "# Name: " + entry.name + Environment.NewLine;
|
|
// 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}" + Environment.NewLine, i, entry.hostname, entry.port,
|
|
i == 0 ? "" : "#");
|
|
}
|
|
|
|
byte[] outBytes = Encoding.ASCII.GetBytes(contents);
|
|
|
|
writer.Write(outBytes, 0, outBytes.Length);
|
|
writer.Close();
|
|
}
|
|
}
|
|
}
|