Unknown check sum in IteamAll.lod
#8

I'm writing my own editors =)

That's why I asked this question

Hope, this bytes (C1 D8 FF FF) aren't so important Big Grin

Here's a bit of code, if someone needs: (author [member=filix_93] )

 

 

namespace Checksum
{
using System;
using System.Diagnostics;
using System.IO;

public static class DoWork
{
public static int CalculateSum(string filepath, int size)
{
int num = 0;
BinaryReader reader = new BinaryReader(File.Open(filepath, FileMode.Open));
try
{
for (int i = 0; i < size; i += 20)
{
reader.BaseStream.Seek((long) i, SeekOrigin.Begin);
num += reader.ReadInt32();
}
reader.Close();
}
catch (Exception exception)
{
Debug.WriteLine(exception);
throw exception;
}
finally
{
if (reader != null)
{
reader.Dispose();
}
}
return num;
}

public static bool CheckSumExist(string filepath)
{
return (GetCurrentSum(filepath) == CalculateSum(filepath, GetFileSize(filepath)));
}

public static bool EncodeFile(string filepath)
{
try
{
BinaryWriter writer;
int num;
Exception exception;
if (!CheckSumExist(filepath))
{
num = CalculateSum(filepath, GetFileSize(filepath));
writer = new BinaryWriter(File.OpenWrite(filepath));
try
{
writer.BaseStream.Seek(0L, SeekOrigin.End);
writer.Write(num);
writer.Close();
}
catch (Exception exception1)
{
exception = exception1;
Debug.WriteLine(exception);
throw exception;
}
finally
{
if (writer != null)
{
writer.Dispose();
}
}
return true;
}
num = CalculateSum(filepath, GetFileSize(filepath));
writer = new BinaryWriter(File.OpenWrite(filepath));
try
{
writer.BaseStream.Seek(-4L, SeekOrigin.End);
writer.Write(num);
writer.Close();
}
catch (Exception exception2)
{
exception = exception2;
Debug.WriteLine(exception);
throw exception;
}
finally
{
if (writer != null)
{
writer.Dispose();
}
}
return true;
}
catch
{
return false;
}
}

public static int GetCurrentSum(string filepath)
{
int num = 0;
BinaryReader reader = new BinaryReader(File.Open(filepath, FileMode.Open));
try
{
reader.BaseStream.Seek(-4L, SeekOrigin.End);
num = reader.ReadInt32();
reader.Close();
}
catch (Exception exception)
{
Debug.WriteLine(exception);
throw exception;
}
finally
{
if (reader != null)
{
reader.Dispose();
}
}
return num;
}

public static int GetFileSize(string filepath)
{
return Convert.ToInt32(new FileInfo(filepath).Length);
}
}
}

 

 

Solved.



Messages In This Thread
[No subject] - by Maxes727 - 06-30-2013, 09:50 AM
[No subject] - by Maxes727 - 07-01-2013, 05:58 PM
[No subject] - by lawilas805 - 01-09-2016, 03:47 PM
[No subject] - by ZaTii - 01-09-2016, 04:23 PM
[No subject] - by lawilas805 - 01-09-2016, 05:02 PM
[No subject] - by lawilas805 - 01-09-2016, 09:11 PM
[No subject] - by ZaTii - 01-09-2016, 10:10 PM
[No subject] - by lawilas805 - 01-09-2016, 11:01 PM
[No subject] - by Wizatek - 01-22-2016, 12:53 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)