Skip to content

Commit

Permalink
Remove obsolete code
Browse files Browse the repository at this point in the history
Misc formatting changes
  • Loading branch information
Exactol committed Dec 21, 2024
1 parent a264c27 commit 0366d15
Show file tree
Hide file tree
Showing 27 changed files with 311 additions and 305 deletions.
10 changes: 9 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_explicit_tuple_names = true : suggestion
dotnet_style_explicit_tuple_names = true:suggestion

# Non-private static fields are PascalCase
dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.severity = suggestion
Expand Down Expand Up @@ -193,6 +193,12 @@ end_of_line = crlf
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_diagnostic.CA1416.severity = none

# CSharp code style settings:
[*.cs]
Expand Down Expand Up @@ -269,3 +275,5 @@ csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_prefer_system_threading_lock = true:suggestion
5 changes: 3 additions & 2 deletions CompilePalX/CompilePalX.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0-windows7.0</TargetFramework>
<TargetFramework>net9.0-windows</TargetFramework>
<OutputType>WinExe</OutputType>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<UseWPF>True</UseWPF>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<SelfContained>True</SelfContained>
<DebugType>embedded</DebugType>
<PlatformName>windows</PlatformName>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>CompilePalIcon.ico</ApplicationIcon>
Expand Down
147 changes: 73 additions & 74 deletions CompilePalX/Compilers/BSPPack/AssetUtils.cs

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions CompilePalX/Compilers/BSPPack/BSP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class BSP
public KeyValuePair<string, string> soundscape { get; set; }
public KeyValuePair<string, string> detail { get; set; }
public KeyValuePair<string, string> nav { get; set; }
public List<KeyValuePair<string, string>> res { get; } = new List<KeyValuePair<string, string>>();
public List<KeyValuePair<string, string>> res { get; } = [];
public KeyValuePair<string, string> kv { get; set; }
public KeyValuePair<string, string> txt { get; set; }
public KeyValuePair<string, string> jpg { get; set; }
Expand Down Expand Up @@ -126,12 +126,12 @@ public BSP(FileInfo file)

public void buildEntityList(FileStream bsp, BinaryReader reader)
{
entityList = new List<Dictionary<string, string>>();
entityListArrayForm = new List<List<Tuple<string, string>>>();
entityList = [];
entityListArrayForm = [];

bsp.Seek(offsets[0].Key, SeekOrigin.Begin);
byte[] ent = reader.ReadBytes(offsets[0].Value);
List<byte> ents = new List<byte>();
List<byte> ents = [];

const int LCURLY = 123;
const int RCURLY = 125;
Expand Down Expand Up @@ -174,7 +174,7 @@ public void buildEntityList(FileStream bsp, BinaryReader reader)
}
entityList.Add(entity);
entityListArrayForm.Add(entityArrayFormat);
ents = new List<byte>();
ents = [];
}
}
}
Expand All @@ -185,7 +185,7 @@ public void buildTextureList(FileStream bsp, BinaryReader reader)

string mapname = bsp.Name.Split('\\').Last().Split('.')[0];

TextureList = new List<string>();
TextureList = [];
bsp.Seek(offsets[43].Key, SeekOrigin.Begin);
TextureList = new List<string>(Encoding.ASCII.GetString(reader.ReadBytes(offsets[43].Value)).Split('\0'));
for (int i = 0; i < TextureList.Count; i++)
Expand All @@ -197,7 +197,7 @@ public void buildTextureList(FileStream bsp, BinaryReader reader)
}

// find skybox materials
Dictionary<string, string> worldspawn = entityList.FirstOrDefault(item => item["classname"] == "worldspawn", new Dictionary<string, string>());
Dictionary<string, string> worldspawn = entityList.FirstOrDefault(item => item["classname"] == "worldspawn", []);
if (worldspawn.ContainsKey("skyname"))
foreach (string s in new string[] { "", "bk", "dn", "ft", "lf", "rt", "up" })
{
Expand All @@ -217,8 +217,8 @@ public void buildEntTextureList()
{
// builds the list of textures referenced in entities

List<string> materials = new List<string>();
HashSet<string> skybox_swappers = new HashSet<string>();
List<string> materials = [];
HashSet<string> skybox_swappers = [];

foreach (Dictionary<string, string> ent in entityList)
{
Expand Down Expand Up @@ -349,7 +349,7 @@ public void buildEntTextureList()
}

// format and add materials
EntTextureList = new List<string>();
EntTextureList = [];
foreach (string material in materials)
{
string materialpath = material;
Expand All @@ -364,7 +364,7 @@ public void buildModelList(FileStream bsp, BinaryReader reader)
{
// builds the list of models that are from prop_static

ModelList = new List<string>();
ModelList = [];
// getting information on the gamelump
int propStaticId = 0;
bsp.Seek(offsets[35].Key, SeekOrigin.Begin);
Expand Down Expand Up @@ -413,7 +413,7 @@ public void buildModelList(FileStream bsp, BinaryReader reader)
modelSkinList = new List<int>[modelCount]; // stores the ids of used skins

for (int i = 0; i < modelCount; i++)
modelSkinList[i] = new List<int>();
modelSkinList[i] = [];

for (int i = 0; i < propCount; i++)
{
Expand All @@ -432,7 +432,7 @@ public void buildEntModelList()
{
// builds the list of models referenced in entities

EntModelList = new List<string>();
EntModelList = [];
foreach (Dictionary<string, string> ent in entityList)
{
foreach (KeyValuePair<string, string> prop in ent)
Expand Down Expand Up @@ -480,7 +480,7 @@ public void buildEntModelList()
public void buildEntSoundList()
{
// builds the list of sounds referenced in entities
EntSoundList = new List<string>();
EntSoundList = [];
foreach (Dictionary<string, string> ent in entityList)
foreach (KeyValuePair<string, string> prop in ent)
{
Expand Down Expand Up @@ -522,7 +522,7 @@ public void buildEntSoundList()
// color correction, etc.
public void buildMiscList()
{
MiscList = new List<string>();
MiscList = [];

// find color correction files
foreach (Dictionary<string, string> cc in entityList.Where(item => item["classname"].StartsWith("color_correction")))
Expand Down Expand Up @@ -550,7 +550,7 @@ public void buildMiscList()

public void buildParticleList()
{
ParticleList = new List<string>();
ParticleList = [];
foreach (Dictionary<string, string> ent in entityList)
foreach (KeyValuePair<string, string> particle in ent)
if (particle.Key.ToLower() == "effect_name")
Expand Down
28 changes: 14 additions & 14 deletions CompilePalX/Compilers/BSPPack/Pack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public BSPPack()

public static KeyValuePair<string, string> particleManifest;

private List<string> sourceDirectories = new List<string>();
private List<string> sourceDirectories = [];
private string outputFile = "BSPZipFiles\\files.txt";

public override void Run(CompileContext context, CancellationToken cancellationToken)
{
CompileErrors = new List<Error>();
CompileErrors = [];

if (!CanRun(context)) return;

Expand All @@ -71,10 +71,10 @@ public override void Run(CompileContext context, CancellationToken cancellationT
char[] paramChars = GetParameterString().ToCharArray();
List<string> parameters = ParseParameters(paramChars);

List<string> includeFiles = new List<string>();
List<string> excludeFiles = new List<string>();
List<string> excludeDirs = new List<string>();
List<string> excludedVpkFiles = new List<string>();
List<string> includeFiles = [];
List<string> excludeFiles = [];
List<string> excludeDirs = [];
List<string> excludedVpkFiles = [];

try
{
Expand Down Expand Up @@ -255,7 +255,7 @@ public override void Run(CompileContext context, CancellationToken cancellationT
return;
}

AssetUtils.findBspUtilityFiles(map, sourceDirectories, renamenav, genParticleManifest);
AssetUtils.FindBspUtilityFiles(map, sourceDirectories, renamenav, genParticleManifest);

// give files unique names based on map so they dont get overwritten
if (dryrun)
Expand All @@ -270,7 +270,7 @@ public override void Run(CompileContext context, CancellationToken cancellationT

string unpackDir = System.IO.Path.GetTempPath() + Guid.NewGuid();
UnpackBSP(unpackDir);
AssetUtils.findBspPakDependencies(map, unpackDir);
AssetUtils.FindBspPakDependencies(map, unpackDir);

CompilePalLogger.LogLine("Initializing pak file...");
PakFile pakfile = new PakFile(map, sourceDirectories, includeFiles, excludeFiles, excludeDirs,
Expand Down Expand Up @@ -639,14 +639,14 @@ static void p_OutputDataReceived(object sender, DataReceivedEventArgs e)

public static List<string> GetSourceDirectories(string gamePath, bool verbose = true)
{
List<string> sourceDirectories = new List<string>();
List<string> sourceDirectories = [];
string gameInfoPath = System.IO.Path.Combine(gamePath, "gameinfo.txt");
string rootPath = Directory.GetParent(gamePath).ToString();

if (!File.Exists(gameInfoPath))
{
CompilePalLogger.LogCompileError($"Couldn't find gameinfo.txt at {gameInfoPath}", new Error($"Couldn't find gameinfo.txt at {gameInfoPath}", ErrorSeverity.Error));
return new();
return [];
}

using (var gameInfoFile = File.OpenRead(gameInfoPath))
Expand All @@ -656,22 +656,22 @@ public static List<string> GetSourceDirectories(string gamePath, bool verbose =
{
CompilePalLogger.LogLineDebug($"Failed to parse GameInfo: {gameInfo}");
CompilePalLogger.LogCompileError($"Failed to parse GameInfo", new Error($"Failed to parse GameInfo", ErrorSeverity.Error));
return new();
return [];
}

if (gameInfo.Name != "GameInfo")
{
CompilePalLogger.LogLineDebug($"Failed to parse GameInfo: {gameInfo}");
CompilePalLogger.LogCompileError($"Failed to parse GameInfo, did not find GameInfo block\n", new Error($"Failed to parse GameInfo, did not find GameInfo block", ErrorSeverity.Error));
return new();
return [];
}

var searchPaths = gameInfo["FileSystem"]?["SearchPaths"] as IEnumerable<KVObject>;
if (searchPaths is null)
{
CompilePalLogger.LogLineDebug($"Failed to parse GameInfo: {gameInfo}");
CompilePalLogger.LogCompileError($"Failed to parse GameInfo, did not find FileSystem.SearchPaths block\n", new Error($"Failed to parse GameInfo, did not find FileSystem.SearchPaths block", ErrorSeverity.Error));
return new();
return [];
}

foreach (var searchPathObject in searchPaths)
Expand Down Expand Up @@ -961,7 +961,7 @@ private static string GetInfoValue(string line)
// parses parameters that can contain '-' in their values. Ex. filepaths
private static List<string> ParseParameters(char[] paramChars)
{
List<string> parameters = new List<string>();
List<string> parameters = [];
bool inQuote = false;
StringBuilder tempParam = new StringBuilder();

Expand Down
22 changes: 11 additions & 11 deletions CompilePalX/Compilers/BSPPack/PakFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void AddGenericFile(string internalPath, string externalPath)
break;
case ".res":
AddInternalFile(internalPath, externalPath);
foreach (string material in AssetUtils.findResMaterials(externalPath))
foreach (string material in AssetUtils.FindResMaterials(externalPath))
AddTexture(material);
break;
case ".nut":
Expand Down Expand Up @@ -182,7 +182,7 @@ public PakFile(BSP bsp, List<string> sourceDirectories, List<string> includeFile
{
if (AddFile(bsp.particleManifest, (b => b.particleManifest = default), bsp))
{
foreach (string particle in AssetUtils.findManifestPcfs(bsp.particleManifest.Value))
foreach (string particle in AssetUtils.FindManifestPcfs(bsp.particleManifest.Value))
AddParticle(particle);
}
}
Expand All @@ -191,7 +191,7 @@ public PakFile(BSP bsp, List<string> sourceDirectories, List<string> includeFile
{
if (AddFile(bsp.soundscape, (b => b.soundscape = default), bsp))
{
foreach (string sound in AssetUtils.findSoundscapeSounds(bsp.soundscape.Value))
foreach (string sound in AssetUtils.FindSoundscapeSounds(bsp.soundscape.Value))
AddSound(sound);
}
}
Expand All @@ -200,7 +200,7 @@ public PakFile(BSP bsp, List<string> sourceDirectories, List<string> includeFile
{
if (AddFile(bsp.soundscript, (b => b.soundscript = default), bsp))
{
foreach (string sound in AssetUtils.findSoundscapeSounds(bsp.soundscript.Value))
foreach (string sound in AssetUtils.FindSoundscapeSounds(bsp.soundscript.Value))
AddSound(sound);
}
}
Expand Down Expand Up @@ -236,7 +236,7 @@ public PakFile(BSP bsp, List<string> sourceDirectories, List<string> includeFile
{
if (AddFile(res, null, bsp))
{
foreach (string material in AssetUtils.findResMaterials(res.Value))
foreach (string material in AssetUtils.FindResMaterials(res.Value))
AddTexture(material);
}

Expand Down Expand Up @@ -302,8 +302,8 @@ public void AddModel(string internalPath, List<int> skins = null)
if (AddInternalFile(internalPath, externalPath))
{
mdlcount++;
List<string> vtxMaterialNames = new List<string>();
foreach (string reference in AssetUtils.findMdlRefs(internalPath))
List<string> vtxMaterialNames = [];
foreach (string reference in AssetUtils.FindMdlRefs(internalPath))
{
string ext_path = FindExternalFile(reference);

Expand All @@ -314,7 +314,7 @@ public void AddModel(string internalPath, List<int> skins = null)
AddInternalFile(reference, ext_path);

if (reference.EndsWith(".phy"))
foreach (string gib in AssetUtils.findPhyGibs(ext_path))
foreach (string gib in AssetUtils.FindPhyGibs(ext_path))
AddModel(gib);

if (reference.EndsWith(".vtx"))
Expand All @@ -334,7 +334,7 @@ public void AddModel(string internalPath, List<int> skins = null)
Tuple<List<string>, List<string>> mdlMatsAndModels;
try
{
mdlMatsAndModels = AssetUtils.findMdlMaterialsAndModels(externalPath, skins, vtxMaterialNames);
mdlMatsAndModels = AssetUtils.FindMdlMaterialsAndModels(externalPath, skins, vtxMaterialNames);
}
catch (Exception e)
{
Expand All @@ -359,9 +359,9 @@ public void AddTexture(string internalPath)
if (AddInternalFile(internalPath, externalPath))
{
vmtcount++;
foreach (string vtf in AssetUtils.findVmtTextures(externalPath))
foreach (string vtf in AssetUtils.FindVmtTextures(externalPath))
AddInternalFile(vtf, FindExternalFile(vtf));
foreach (string vmt in AssetUtils.findVmtMaterials(externalPath))
foreach (string vmt in AssetUtils.FindVmtMaterials(externalPath))
AddTexture(vmt);
}
}
Expand Down
11 changes: 4 additions & 7 deletions CompilePalX/Compilers/CompileExecutable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@

namespace CompilePalX.Compilers
{
class CompileExecutable : CompileProcess
class CompileExecutable(string metadata, string? parameterFolder = null) : CompileProcess(metadata, parameterFolder)
{
public CompileExecutable(string metadata, string? parameterFolder = null) : base(metadata, parameterFolder) { }


public override void Run(CompileContext c, CancellationToken cancellationToken)
{
CompileErrors = new List<Error>();
CompileErrors = [];

if (!CanRun(c)) return;

Expand Down Expand Up @@ -65,7 +62,7 @@ public override void Run(CompileContext c, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
CompilePalLogger.LogDebug($"Cancelled {this.Metadata.Name}");
CompilePalLogger.LogDebug($"Cancelled {Metadata.Name}");
return;
}
Process.Start();
Expand Down Expand Up @@ -106,7 +103,7 @@ private void ReadOutput(CancellationToken cancellationToken)
if (read == null)
read = Process.StandardOutput.ReadAsync(buffer, 0, buffer.Length);

read.Wait(100); // an arbitrary timeout
read.Wait(100, cancellationToken); // an arbitrary timeout

if (read.IsCompleted)
{
Expand Down
Loading

0 comments on commit 0366d15

Please sign in to comment.