79 lines
2.4 KiB
C#
79 lines
2.4 KiB
C#
using CaeGlobals;
|
|
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
#pragma warning disable IDE0130
|
|
|
|
namespace CPSO.Commands
|
|
{
|
|
[Serializable]
|
|
public class CSaveToPmx : SaveCommand, IFileCommand
|
|
{
|
|
// Variables
|
|
private byte[] _hash;
|
|
|
|
// Properties
|
|
public string FileName { get; }
|
|
public byte[] Hash
|
|
{
|
|
get => _hash;
|
|
set => _hash = value;
|
|
}
|
|
|
|
// Constructor
|
|
public CSaveToPmx(string fileName)
|
|
: base("Save to file")
|
|
{
|
|
FileName = Tools.GetLocalPath(fileName);
|
|
_hash = null;
|
|
}
|
|
|
|
|
|
// Methods
|
|
private byte[] GetHash()
|
|
{
|
|
byte[] hash = null;
|
|
string globalFileName = Tools.GetGlobalPath(FileName);
|
|
//
|
|
if (File.Exists(globalFileName))
|
|
{
|
|
using (FileStream fop = File.OpenRead(Tools.GetGlobalPath(FileName)))
|
|
{
|
|
hash = System.Security.Cryptography.SHA1.Create().ComputeHash(fop);
|
|
string unused = BitConverter.ToString(hash);
|
|
}
|
|
}
|
|
//
|
|
return hash;
|
|
}
|
|
|
|
public bool IsFileHashUnchanged()
|
|
{
|
|
byte[] hash = GetHash();
|
|
if (hash == null || _hash == null)
|
|
{
|
|
return false;
|
|
}
|
|
// ReSharper disable once RedundantIfElseBlock
|
|
else
|
|
{
|
|
return hash.SequenceEqual(_hash);
|
|
}
|
|
}
|
|
|
|
public override bool Execute(Controller receiver)
|
|
{
|
|
receiver.SaveToPmx(Tools.GetGlobalPath(FileName));
|
|
//
|
|
_hash = GetHash();
|
|
//
|
|
return true;
|
|
}
|
|
|
|
public override string GetCommandString()
|
|
{
|
|
return _dateCreated.ToString("MM/dd/yy HH:mm:ss") + " " + "Model saved to file: " + FileName;
|
|
}
|
|
}
|
|
}
|