Repository navigation
Expand file tree
/
Copy pathGarrysModConfigForm.cs
More file actions
101 lines (92 loc) · 4.19 KB
/
Copy pathGarrysModConfigForm.cs
File metadata and controls
101 lines (92 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
namespace SourceMultiToolCSharp
{
public partial class GarrysModConfigForm : Form
{
public GarrysModConfigForm()
{
InitializeComponent();
}
Dictionary<string,string> gmodAddons = new Dictionary<string,string>();
string gmodDirectory = "";
private void GarrysModConfigForm_Shown(object sender, EventArgs e)
{
// Populate our menu with the games they have
foreach (SourceGame game in MainMenuForm.listOfSourceGames)
{
if (game.Installed)
{
if (game.SteamName == "GarrysMod")
{
// Now we search their addons folder for folders
gmodDirectory = game.Directory;
var garrysModAddonFolders = Directory.GetDirectories(game.Directory + "/garrysmod/addons");
foreach (string addon in garrysModAddonFolders)
{
string addonName = "Addon: "+addon.Remove(0, game.Directory.Length + 18);
listbox_gmodContent.Items.Add(addonName);
gmodAddons.Add(addonName, addon);
}
}
else if (game.Mod)
{
string modName = game.ProperName;
listbox_gmodContent.Items.Add(modName);
}
else
{
listbox_gmodContent.Items.Add(game.ProperName);
}
}
}
}
private void button_gmodAddonsFolder_Click(object sender, EventArgs e)
{
Process.Start(gmodDirectory + "/garrysmod/addons");
}
private void button_gmodSave_Click(object sender, EventArgs e)
{
//Backup the file if it exists
if(File.Exists(gmodDirectory+"/garrysmod/cfg/mount.cfg"))
{
File.Copy(gmodDirectory + "/garrysmod/cfg/mount.cfg", gmodDirectory + "/garrysmod/cfg/mount.cfg.backup",true);
}
using (StreamWriter writer = new StreamWriter(gmodDirectory + "/garrysmod/cfg/mount.cfg"))
{
writer.WriteLine("// Use this file to mount additional paths to the filesystem");
writer.WriteLine("// DO NOT add a slash to the end of the filename \n\n");
writer.WriteLine("\"mountcfg\"");
writer.WriteLine("{");
foreach (string content in listbox_gmodContent.CheckedItems)
{
// TODO: This could be better optimized
foreach (SourceGame game in MainMenuForm.listOfSourceGames)
{
if(game.ProperName == content)
{
if (game.Mod)
{
writer.WriteLine("\"" + game.SourceName + "\" " + "\"" + game.Directory + "\"");
}
else
{
writer.WriteLine("\"" + game.SourceName + "\" " + "\"" + game.Directory + "\\" + game.SourceName + "\"");
}
}
}
if (gmodAddons.ContainsKey(content))
{
writer.WriteLine("\"" + content.Remove(0, 7) + "\" " + "\"" + gmodAddons[content] + "\"");
}
}
writer.WriteLine("}");
System.Windows.Forms.MessageBox.Show("WARNING: This does not auto pack this content into your map you must still do this on your own!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning);
System.Windows.Forms.MessageBox.Show("Save Complete!", "Garry's Mod Configuration Saved", MessageBoxButtons.OK);
}
}
}
}