Skip to content

Commit

Permalink
Added mod name translation
Browse files Browse the repository at this point in the history
  • Loading branch information
UAVXP committed Apr 19, 2017
1 parent 084a5c9 commit 6414879
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 30 deletions.
62 changes: 62 additions & 0 deletions LibList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Text;

using System.IO;

namespace ModLauncher
{
class LibList
{
private string Filename { get; set; }

public LibList(string gamePath, string modDirectory)
{
this.Filename = gamePath + "\\" + modDirectory + "\\scripts\\liblist.gam";
Console.WriteLine(this.Filename);
}

private bool GetValue(string line, string forSearch, out string value)
{
value = "";

try
{
line = line.Trim();
int forSearchLength = forSearch.Length;
int findMaterial = line.IndexOf(forSearch);
if (findMaterial < 0) // If there's no forSearch in line
return false;
if (findMaterial > 0) // If forSearch is further than 0 symbol, i.e.: "name" "game" - it's just value, not parameter name
return false;

value = line.Substring(forSearchLength + 1).Replace('/', '\\').Trim(trimChars: '"');

return true;
}
catch { }

return false;
}

public string GetGameName()
{
string[] file = new string[] { };
try
{
file = File.ReadAllLines(this.Filename);
}
catch { }

foreach (string line in file)
{
string value = "";

bool foundGameName = GetValue(line, "game", out value);
if (foundGameName)
return value;
}
return "";
}
}
}
65 changes: 37 additions & 28 deletions MainForm.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//#define TRANSLATION 1

using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
Expand Down Expand Up @@ -40,7 +38,7 @@ protected override CreateParams CreateParams
}
}


List<Mod> mods = new List<Mod>();

public MainForm()
{
Expand Down Expand Up @@ -198,8 +196,7 @@ public static string getModDirectory()
return regValue;
}

#if TRANSLATION
private void TranslateModDirectory(ref string dir)
private string TranslateModDirectory(string dir)
{
dir = dir.ToLower();
switch (dir)
Expand All @@ -220,31 +217,50 @@ private void TranslateModDirectory(ref string dir)
default:
break;
}

return dir;
}
#endif

public void RefreshModList()
{
modList.Items.Clear();
List<string> listOfMods = new List<string>();
mods.Clear();

foreach (string dir in Directory.GetDirectories(gamePath))
{
if (isModDirectory(dir))
{
listOfMods.Add(dir.Substring(dir.LastIndexOf('\\') + 1));
string ddir = dir.Substring(dir.LastIndexOf('\\') + 1);

LibList liblist = new LibList(gamePath, ddir);
string gamename = liblist.GetGameName();

if (gamename == "") // There's still no information about this mod at liblist.gam
{
gamename = TranslateModDirectory(ddir); // Trying to translate mod directory with known names
}

Console.WriteLine("Game: " + gamename);

Mod mod = new Mod {
Dir = ddir,
Name = ((gamename != "") ? gamename : ddir)
};
mods.Add(mod);
}
}
modList.Items.AddRange(listOfMods.ToArray());
foreach (Mod mod in mods)
{
modList.Items.Add(mod.Name);
}

// Choosing saved mod
string choosedGameMod = getModDirectory();
int k = 0;
bool isModFound = false;
ComboBox.ObjectCollection listItems = modList.Items;
foreach (string val in listItems)
foreach (Mod val in mods)
{
// Console.WriteLine(val + " - " + choosedGameMod);
if (val == choosedGameMod)
if (val.Dir == choosedGameMod)
{
modList.SelectedIndex = k;
isModFound = true;
Expand All @@ -255,26 +271,16 @@ public void RefreshModList()
if (!isModFound)
{
k = 0;
foreach (string val in listItems)
foreach (Mod val in mods)
{
if (val.IndexOf(choosedGameMod) >= 0)
if (val.Dir.IndexOf(choosedGameMod) >= 0)
{
modList.SelectedIndex = k;
break;
}
k++;
}
}

#if TRANSLATION
// Translating
for (int i = 0; i < modList.Items.Count; i++)
{
string oldValue = (string)modList.Items[i];
TranslateModDirectory(ref oldValue);
modList.Items[i] = oldValue;
}
#endif
}

private void MainForm_Load(object sender, EventArgs e)
Expand Down Expand Up @@ -329,7 +335,9 @@ private void parametersText_Leave(object sender, EventArgs e)

private void startProcess(string name)
{
string choosedMod = modList.SelectedItem.ToString();
// string choosedMod = modList.SelectedItem.ToString();
string choosedMod = mods[modList.SelectedIndex].Dir;
Console.WriteLine("Trying to run " + choosedMod);

// Environment.SetEnvironmentVariable("VPROJECT", gamePath + "\\" + getModDirectory());
Environment.SetEnvironmentVariable("VPROJECT", gamePath + "\\" + choosedMod);
Expand Down Expand Up @@ -410,7 +418,8 @@ private void btnRefresh_Click(object sender, EventArgs e)

private void modList_TextChanged(object sender, EventArgs e)
{
string choosedMod = (sender as ComboBox).SelectedItem.ToString();
// string choosedMod = (sender as ComboBox).SelectedItem.ToString();
string choosedMod = mods[modList.SelectedIndex].Dir;
setRegistryValue("LNGameMod", choosedMod);

// Saving parameters into registry
Expand Down
12 changes: 12 additions & 0 deletions Mod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ModLauncher
{
class Mod
{
public string Dir { get; set; }
public string Name { get; set; }
}
}
1 change: 1 addition & 0 deletions ModLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="LibList.cs" />
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("VXP")]
[assembly: AssemblyProduct("ModLauncher")]
[assembly: AssemblyCopyright("Copyright © VXP 2016")]
[assembly: AssemblyTrademark("2016 Valve Corporation. All rights reserved. Valve, the Valve logo, Half-Life, the Half-Life logo are trademarks and/or registered trademarks of Valve Corporation. All other trademarks are property of their respective owners.")]
[assembly: AssemblyCopyright("Copyright © VXP 2017")]
[assembly: AssemblyTrademark("2017 Valve Corporation. All rights reserved. Valve, the Valve logo, Half-Life, the Half-Life logo are trademarks and/or registered trademarks of Valve Corporation. All other trademarks are property of their respective owners.")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
Expand Down

0 comments on commit 6414879

Please sign in to comment.