Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions FASTER/Models/BasicCfg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public static class BasicCfgArrays
[Serializable]
public class BasicCfg : INotifyPropertyChanged
{
private string language = "English";

private uint viewDistance = 2000;
private double terrainGrid = 25;

Expand All @@ -28,6 +30,7 @@ public class BasicCfg : INotifyPropertyChanged
private ushort maxPacketSize = 1400;

private string basicContent;
private string a3cfgContent;

public string BasicContent
{
Expand All @@ -38,7 +41,27 @@ public string BasicContent
RaisePropertyChanged("BasicContent");
}
}

public string Arma3CfgContent
{
get => a3cfgContent;
set
{
a3cfgContent = value;
RaisePropertyChanged("Arma3CfgContent");
}
}

public string Language
{
get => language;
set
{
language = value;
RaisePropertyChanged("Language");
}
}

public uint ViewDistance
{
get => viewDistance;
Expand Down Expand Up @@ -186,12 +209,15 @@ public string PerfPreset
}

public BasicCfg()
{ BasicContent = ProcessFile(); }
{
BasicContent = ProcessBasicFile();
Arma3CfgContent = ProcessArma3CfgFile();
}

public string ProcessFile()
public string ProcessBasicFile()
{
string output = "// These options are created by default\r\n"
+ "language=\"English\";\r\n"
+ $"language=\"{language}\";\r\n"
+ "adapter=-1;\r\n"
+ "3D_Performance=1.000000;\r\n"
+ "Resolution_W=800;\r\n"
Expand All @@ -217,14 +243,26 @@ public string ProcessFile()
+ $"class sockets{{ maxPacketSize = {maxPacketSize};}};";
return output;
}

public string ProcessArma3CfgFile()
{
string output = "steamLanguage=\"\";\r\n"
+ $"language=\"{language}\";\r\n";

return output;
}

public event PropertyChangedEventHandler PropertyChanged;

private void RaisePropertyChanged(string property)
{
if (PropertyChanged == null) return;
PropertyChanged(this, new PropertyChangedEventArgs(property));
if (property != "BasicContent") BasicContent = ProcessFile();
if (property != "BasicContent" && property != "Arma3CfgContent")
{
BasicContent = ProcessBasicFile();
Arma3CfgContent = ProcessArma3CfgFile();
}
}
}
}
9 changes: 6 additions & 3 deletions FASTER/Models/ServerProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ internal static void AddServerProfile(string profileName)
var currentProfiles = Properties.Settings.Default.Profiles;
var p = new ServerProfile(profileName);
p.ServerCfg.ServerCfgContent = p.ServerCfg.ProcessFile();
p.BasicCfg.BasicContent = p.BasicCfg.ProcessFile();
p.BasicCfg.BasicContent = p.BasicCfg.ProcessBasicFile();
p.BasicCfg.Arma3CfgContent = p.BasicCfg.ProcessArma3CfgFile();
p.ArmaProfile.ArmaProfileContent = p.ArmaProfile.ProcessFile();
currentProfiles.Add(p);
Properties.Settings.Default.Profiles = currentProfiles;
Expand Down Expand Up @@ -428,7 +429,8 @@ public ServerProfile(string name, bool createFolder = true)
BasicCfg = new BasicCfg();
ServerCfg.ServerCfgContent = ServerCfg.ProcessFile();
ArmaProfile.ArmaProfileContent = ArmaProfile.ProcessFile();
BasicCfg.BasicContent = BasicCfg.ProcessFile();
BasicCfg.BasicContent = BasicCfg.ProcessBasicFile();
BasicCfg.Arma3CfgContent = BasicCfg.ProcessArma3CfgFile();

if (createFolder)
{ Directory.CreateDirectory(Path.Combine(Properties.Settings.Default.serverPath, "Servers", Id)); }
Expand All @@ -443,7 +445,8 @@ public ServerProfile()
BasicCfg = new BasicCfg();
ServerCfg.ServerCfgContent = ServerCfg.ProcessFile();
ArmaProfile.ArmaProfileContent = ArmaProfile.ProcessFile();
BasicCfg.BasicContent = BasicCfg.ProcessFile();
BasicCfg.BasicContent = BasicCfg.ProcessBasicFile();
BasicCfg.Arma3CfgContent = BasicCfg.ProcessArma3CfgFile();
}

public void GenerateNewId()
Expand Down
3 changes: 3 additions & 0 deletions FASTER/ViewModel/ProfileViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,19 @@ internal void SaveProfile()
string config = Path.Combine(Profile.ArmaPath, "Servers", Profile.Id, "server_config.cfg");
string basic = Path.Combine(Profile.ArmaPath, "Servers", Profile.Id, "server_basic.cfg");
string serverProfile = Path.Combine(Profile.ArmaPath, "Servers", Profile.Id, "users", Profile.Id, $"{Profile.Id}.Arma3Profile");
string arma3Cfg = Path.Combine(Profile.ArmaPath, "Servers", Profile.Id, "users", Environment.UserName, $"Arma3.cfg");

//Creating profile directory
Directory.CreateDirectory(Path.Combine(Profile.ArmaPath, "Servers", Profile.Id, "users", Profile.Id));
Directory.CreateDirectory(Path.Combine(Profile.ArmaPath, "Servers", Profile.Id, "users", Environment.UserName));

//Writing files
try
{
File.WriteAllLines(config, Profile.ServerCfg.ServerCfgContent.Replace("\r", "").Split('\n'));
File.WriteAllLines(basic, Profile.BasicCfg.BasicContent.Replace("\r", "").Split('\n'));
File.WriteAllLines(serverProfile, Profile.ArmaProfile.ArmaProfileContent.Replace("\r", "").Split('\n'));
File.WriteAllLines(arma3Cfg, Profile.BasicCfg.Arma3CfgContent.Replace("\r", "").Split('\n'));
}
catch
{ DisplayMessage("Could not write the config files. Please ensure the server is not running and retry."); }
Expand Down
3 changes: 2 additions & 1 deletion FASTER/Views/Profile.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<Button Content="{iconPacks:Material Kind=FolderOpen}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Grid.Column="1" Width="{Binding ActualHeight, RelativeSource={RelativeSource Self}}" Height="auto" Margin="5,5,0,5" Style="{StaticResource MahApps.Styles.Button.MetroSquare.Accent}" BorderThickness="0" Padding="3" Click="SelectServerFile"/>
</Grid>
<mah:NumericUpDown Value="{Binding Profile.Port, UpdateSourceTrigger=PropertyChanged}" mah:TextBoxHelper.UseFloatingWatermark="True" mah:TextBoxHelper.Watermark="Port" ToolTip="Port for ArmaServer"/>
<TextBox Text="{Binding Path=Profile.BasicCfg.Language, UpdateSourceTrigger=PropertyChanged}" Margin="0 5" mah:TextBoxHelper.Watermark="Server Language" mah:TextBoxHelper.UseFloatingWatermark="True" />
</StackPanel>
</GroupBox>
<StackPanel Height="10"/>
Expand Down Expand Up @@ -666,7 +667,7 @@
<mah:NumericUpDown Value="{Binding Path=Profile.ServerCfg.SteamProtocolMaxDataSize}" mah:TextBoxHelper.UseFloatingWatermark="True" mah:TextBoxHelper.Watermark="Steam Protocol Max Data Size" Margin="5"/>

<TextBox MinHeight="50" Margin="5" Text="{Binding Path=Profile.ServerCfg.Admins}" AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" mah:TextBoxHelper.UseFloatingWatermark="True" mah:TextBoxHelper.Watermark="Admins IDs (one per line)"/>

</StackPanel>
</Expander>
</StackPanel>
Expand Down
1 change: 1 addition & 0 deletions FASTERTests/Models/BasicCfgTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void BasicCfgGetTest()
Assert.That(_cfg.PerfPreset, Is.EqualTo("Custom"));
Assert.That(_cfg.TerrainGrid, Is.Not.Null);
Assert.That(_cfg.ViewDistance, Is.Not.Null);
Assert.That(_cfg.Language, Is.Not.Null);
}

[Test()]
Expand Down