Skip to content

Commit

Permalink
Fixed warnings (WolvenKit#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
phrisk authored Jan 30, 2021
1 parent 330e3be commit 0433eb5
Show file tree
Hide file tree
Showing 59 changed files with 190 additions and 404 deletions.
8 changes: 4 additions & 4 deletions CP77.CR2W/CR2W/CR2WExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,17 @@ public Cr2wVariableDumpObject GetDumpObject(BinaryReader br)
variable.Variables = TryGetClassVariables(variable.Size);
}
}
catch (Exception e)
catch (Exception)
{

// TODO: Are we intentionally swallowing this?
}


// go to variable end
br.BaseStream.Seek(endoffset, SeekOrigin.Begin);
o.Variables.Add(variable);
}
catch (Exception e)
catch (Exception)
{
return o;
}
Expand Down Expand Up @@ -358,7 +358,7 @@ List<Cr2wVariableDumpObject> TryGetClassVariables(int innersize)
br.BaseStream.Seek(endoffset, SeekOrigin.Begin);
ret.Add(variable);
}
catch (Exception e)
catch (Exception)
{
return null;
}
Expand Down
30 changes: 9 additions & 21 deletions CP77.CR2W/Extensions/StreamExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,27 @@
using RED.CRC32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using CP77.CR2W.Types;

namespace CP77.CR2W
{
public static class StreamExtensions
{
public static T ReadStruct<T>(this Stream m_stream, Crc32Algorithm crc32 = null) where T : struct
{
try
{
var size = Marshal.SizeOf<T>();

var m_temp = new byte[size];
m_stream.Read(m_temp, 0, size);
var size = Marshal.SizeOf<T>();

var handle = GCHandle.Alloc(m_temp, GCHandleType.Pinned);
var item = Marshal.PtrToStructure<T>(handle.AddrOfPinnedObject());
var m_temp = new byte[size];
m_stream.Read(m_temp, 0, size);

if (crc32 != null)
crc32.Append(m_temp);
var handle = GCHandle.Alloc(m_temp, GCHandleType.Pinned);
var item = Marshal.PtrToStructure<T>(handle.AddrOfPinnedObject());

handle.Free();
if (crc32 != null)
crc32.Append(m_temp);

return item;
}
catch (Exception ex)
{
handle.Free();

throw ex;
}

return item;
}
public static T[] ReadStructs<T>(this Stream m_stream, uint count, Crc32Algorithm crc32 = null) where T : struct
{
Expand Down
7 changes: 2 additions & 5 deletions CP77.CR2W/Extensions/W3ReaderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using RED.CRC32;
using System;
using System.Collections.Generic;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using CP77.CR2W.Types;

Expand Down Expand Up @@ -185,7 +182,7 @@ public static string ReadLengthPrefixedStringNullTerminated(this BinaryReader br
if (unknownFlag)
{
throw new NotImplementedException();
readstring = Encoding.Unicode.GetString(br.ReadBytes((len * 2) - 1));
// readstring = Encoding.Unicode.GetString(br.ReadBytes((len * 2) - 1));
}
else
readstring = Encoding.GetEncoding("ISO-8859-1").GetString(br.ReadBytes(len - 1));
Expand Down
9 changes: 1 addition & 8 deletions CP77.CR2W/Modkit/Import.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Catel.IoC;
using WolvenKit.Common.Services;
using CP77.CR2W.Archive;
using CP77.CR2W.Types;
using CP77Tools.Model;
using WolvenKit.Common;
using WolvenKit.Common.DDS;

Expand Down Expand Up @@ -69,7 +62,7 @@ private static CR2WFile ImportXbm(FileInfo rawFile, string textureGroup = null)
{
TexconvWrapper.Convert(rawFile.Directory.FullName, $"{ddsPath}", EUncookExtension.dds);
}
catch (Exception e)
catch (Exception)
{
//TODO: proper exception handling
return null;
Expand Down
9 changes: 2 additions & 7 deletions CP77.CR2W/Modkit/Rebuild.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Catel.IoC;
using WolvenKit.Common.Services;
using WolvenKit.Common;
Expand Down Expand Up @@ -41,7 +39,7 @@ public static CR2WFile TryReadCr2WFile(BinaryReader br)
br.BaseStream.Seek(0, SeekOrigin.Begin);
cr2w.Read(br);
}
catch (Exception e)
catch (Exception)
{
return null;
}
Expand Down Expand Up @@ -73,7 +71,7 @@ public static CR2WFile TryReadCr2WFileHeaders(BinaryReader br)
br.BaseStream.Seek(0, SeekOrigin.Begin);
cr2w.ReadImportsAndBuffers(br);
}
catch (Exception e)
catch (Exception)
{
return null;
}
Expand Down Expand Up @@ -299,9 +297,6 @@ byte[] ReadBuffer(FileInfo buffer)
fs.Seek(128, SeekOrigin.Begin);
return br.ReadBytes((int)fs.Length - 128);
}
break;
default:
break;
}
}
else
Expand Down
3 changes: 1 addition & 2 deletions CP77.CR2W/Modkit/Uncook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
Expand Down Expand Up @@ -254,7 +253,7 @@ public static int Uncook(CR2WFile cr2w, List<byte[]> buffers, ECookedFileFormat
TexconvWrapper.Convert(di.FullName, $"{newpath}", uncookext);
uncooksuccess = true;
}
catch (Exception e)
catch (Exception)
{
uncooksuccess = false;
}
Expand Down
2 changes: 0 additions & 2 deletions CP77.CR2W/Types/cp77/inkVirtualCompoundItemController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.IO;
using CP77.CR2W.Reflection;
using FastMember;
using static CP77.CR2W.Types.Enums;

namespace CP77.CR2W.Types
{
Expand Down
24 changes: 2 additions & 22 deletions CP77.MSTests/ArchiveTests.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Catel.IoC;
using WolvenKit.Common.Services;
using CP77.CR2W;
using CP77.CR2W.Archive;
using Microsoft.Extensions.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using WolvenKit.Common;

namespace CP77.MSTests
{
Expand All @@ -33,18 +17,14 @@ public void Test_Uncook()

}


private void test_archive(string extension = null)
/*private void test_archive(string extension = null)
{
var resultDir = Path.Combine(Environment.CurrentDirectory, TestResultsDirectory);
Directory.CreateDirectory(resultDir);
var success = true;
List<Archive> archives;



}
}*/
}
}
4 changes: 2 additions & 2 deletions CP77Tools/Commands/CR2WCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace CP77Tools.Commands
{
public class CR2WCommand : Command
{
private static string Name = "cr2w";
private static string Description = "Target a specific cr2w (extracted) file and dumps file information.";
private new const string Name = "cr2w";
private new const string Description = "Target a specific cr2w (extracted) file and dumps file information.";

public CR2WCommand() : base(Name, Description)
{
Expand Down
4 changes: 2 additions & 2 deletions CP77Tools/Commands/DumpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace CP77Tools.Commands
{
public class DumpCommand : Command
{
private static string Name = "dump";
private static string Description = "Target an archive or a directory to dump archive information.";
private new const string Name = "dump";
private new const string Description = "Target an archive or a directory to dump archive information.";

public DumpCommand() : base(Name, Description)
{
Expand Down
4 changes: 2 additions & 2 deletions CP77Tools/Commands/ExportCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace CP77Tools.Commands
{
public class ExportCommand : Command
{
private static string Name = "export";
private static string Description = "Export a file or a list of files into raw files.";
private new const string Name = "export";
private new const string Description = "Export a file or a list of files into raw files.";

public ExportCommand() : base(Name, Description)
{
Expand Down
4 changes: 2 additions & 2 deletions CP77Tools/Commands/HashCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace CP77Tools.Commands
{
public class HashCommand : Command
{
private static string Name = "hash";
private static string Description = "Some helper functions related to hashes.";
private new const string Name = "hash";
private new const string Description = "Some helper functions related to hashes.";

public HashCommand() : base(Name, Description)
{
Expand Down
4 changes: 2 additions & 2 deletions CP77Tools/Commands/OodleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace CP77Tools.Commands
{
public class OodleCommand : Command
{
private static string Name = "oodle";
private static string Description = "Some helper functions related to oodle compression.";
private new const string Name = "oodle";
private new const string Description = "Some helper functions related to oodle compression.";

public OodleCommand() : base(Name, Description)
{
Expand Down
4 changes: 2 additions & 2 deletions CP77Tools/Commands/PackCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace CP77Tools.Commands
{
public class PackCommand : Command
{
private static string Name = "pack";
private static string Description = "Pack a folder of files into an .archive file.";
private new const string Name = "pack";
private new const string Description = "Pack a folder of files into an .archive file.";

public PackCommand() : base(Name, Description)
{
Expand Down
4 changes: 2 additions & 2 deletions CP77Tools/Commands/RebuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace CP77Tools.Commands
{
public class RebuildCommand : Command
{
private static string Name = "rebuild";
private static string Description = "Recombine split buffers and textures in a folder.";
private new const string Name = "rebuild";
private new const string Description = "Recombine split buffers and textures in a folder.";

public RebuildCommand() : base(Name, Description)
{
Expand Down
4 changes: 2 additions & 2 deletions CP77Tools/Commands/UnbundleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace CP77Tools.Commands
{
public class UnbundleCommand : Command
{
private static string Name = "unbundle";
private static string Description = "Target an archive to extract files.";
private new const string Name = "unbundle";
private new const string Description = "Target an archive to extract files.";

public UnbundleCommand() : base(Name, Description)
{
Expand Down
4 changes: 2 additions & 2 deletions CP77Tools/Commands/UncookCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace CP77Tools.Commands
{
public class UncookCommand : Command
{
private static string Name = "uncook";
private static string Description = "Target an archive to uncook files.";
private new const string Name = "uncook";
private new const string Description = "Target an archive to uncook files.";

public UncookCommand() : base(Name, Description)
{
Expand Down
4 changes: 2 additions & 2 deletions CP77Tools/Commands/VerifyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace CP77Tools.Commands
{
public class VerifyCommand : Command
{
private static string Name = "verify";
private static string Description = "Some helper functions related to cr2w files.";
private new const string Name = "verify";
private new const string Description = "Some helper functions related to cr2w files.";

public VerifyCommand() : base(Name, Description)
{
Expand Down
Loading

0 comments on commit 0433eb5

Please sign in to comment.