Files
gaseous-server/gaseous-tools/Common.cs
Michael Green 25f1895fe5 Added feature to build collections of ROM's based on a filter (#76)
* fix: added visual feed back for mass rom matching

* chore(deps): EmulatorJS version bump

* chore(deps): nuget package version bump

* feat: added cover art to the emulator

* ci: updated .gitignore

* ci: remove .DS_Store files

* feat: updated the about box, and labeled the IGDB user score

* chore(deps): EmulatorJS version bump

* feat: start of collections build, and styling changes

* fix: updated PlatformMap.json file with more platforms and fixed SNES extensions

* feat: more progress on romsets

* doc: updated readme to include new screenshots and discord link

* fix: repairs an issue where the author column in signatures was too narrow

* chore(deps): EmulatorJS version bump

* feat: Collection build code mostly complete

* fix: renamed collection classes to avoid conflicts in Swagger

* Re-wrote collection builder to correct major bugs and performance

* Completed collection builder and zipper

* API changes completed

* Fixed some last minute Collections API bugs

* Collections mostly complete. Todo: delete button

* Completed collections build
2023-09-01 21:02:15 +10:00

105 lines
2.4 KiB
C#

using System;
using System.Security.Cryptography;
namespace gaseous_tools
{
public class Common
{
/// <summary>
/// Returns IfNullValue if the ObjectToCheck is null
/// </summary>
/// <param name="ObjectToCheck">Any nullable object to check for null</param>
/// <param name="IfNullValue">Any object to return if ObjectToCheck is null</param>
/// <returns></returns>
static public object ReturnValueIfNull(object? ObjectToCheck, object IfNullValue)
{
if (ObjectToCheck == null || ObjectToCheck == System.DBNull.Value)
{
return IfNullValue;
} else
{
return ObjectToCheck;
}
}
static public DateTime ConvertUnixToDateTime(double UnixTimeStamp)
{
DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
dateTime = dateTime.AddSeconds(UnixTimeStamp).ToLocalTime();
return dateTime;
}
public class hashObject
{
public hashObject()
{
}
public hashObject(string FileName)
{
var xmlStream = File.OpenRead(FileName);
var md5 = MD5.Create();
byte[] md5HashByte = md5.ComputeHash(xmlStream);
string md5Hash = BitConverter.ToString(md5HashByte).Replace("-", "").ToLowerInvariant();
_md5hash = md5Hash;
var sha1 = SHA1.Create();
xmlStream.Position = 0;
byte[] sha1HashByte = sha1.ComputeHash(xmlStream);
string sha1Hash = BitConverter.ToString(sha1HashByte).Replace("-", "").ToLowerInvariant();
_sha1hash = sha1Hash;
xmlStream.Close();
}
string _md5hash = "";
string _sha1hash = "";
public string md5hash
{
get
{
return _md5hash;
}
set
{
_md5hash = value;
}
}
public string sha1hash
{
get
{
return _sha1hash;
}
set
{
_sha1hash = value;
}
}
}
public static long DirSize(DirectoryInfo d)
{
long size = 0;
// Add file sizes.
FileInfo[] fis = d.GetFiles();
foreach (FileInfo fi in fis)
{
size += fi.Length;
}
// Add subdirectory sizes.
DirectoryInfo[] dis = d.GetDirectories();
foreach (DirectoryInfo di in dis)
{
size += DirSize(di);
}
return size;
}
}
}