Er ist in C#.
Wer damit was anfangen kann hier ist er:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.IO.Compression;
using System.Security.Cryptography;
namespace Titanium
{
public static class Core
{
public static byte[] CreateList(List<string> lstFiles)
{
string strReturnValue = "";//ver:21\r\n Z:\\ResClient\r\n";
for (int i = 0; i < lstFiles.Count; i++)
{
bool bImportant;
if (bImportant = lstFiles[i].IndexOf(",IMPORTANT") != -1)
{
lstFiles[i] = lstFiles[i].Replace(",IMPORTANT", "");
}
FileInfo fi = new FileInfo(lstFiles[i]);
if (!fi.Exists)
{
DialogResult dr = MessageBox.Show("File " + lstFiles[i] + " was not found.", "File not found", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
if (dr == DialogResult.Abort)
{
return new byte[0];
}
if (dr == DialogResult.Retry)
{
i--;
continue;
}
if (dr == DialogResult.Ignore)
{
continue;
}
}
string strDate = Core.GetDateFormat(fi.LastWriteTime);
if (!bImportant)
{
strReturnValue += string.Format("{0},{1}\r\n", lstFiles[i], fi.Length);
}
else
{
strReturnValue += string.Format("{0},{1},{2}\r\n", lstFiles[i], fi.Length, BitConverter.ToString(MD5.Create().ComputeHash(File.ReadAllBytes(fi.FullName))).Replace("-", ""));
}
}
return DoEncryption(bytes(strReturnValue));
}
static byte[] bytes(string s)
{
byte[] a = new byte[s.Length];
for (int i = 0; i < s.Length; i++)
{
a[i] = (byte)s[i];
}
return a;
}
public static byte[] DoEncryption(byte[] b)
{
if (b.Length < 1)
{
return new byte[0];
}
byte[] dec = new byte[b.Length];
byte bySeed = b[0];
for (int i = 0; i < b.Length; i++)
{
byte by = b[i];
for (int j = 0; j < DECRYPT_PASSWORD.Length; j++)
{
by = (byte)(b[i] ^ 0xFF ^ DECRYPT_PASSWORD[j]);
}
bySeed = by;
dec[i] = by;
}
return dec;
}
public const string DECRYPT_PASSWORD = "barbeque";
public static string GetDateFormat(DateTime dt)
{
int dwHour = dt.Hour;
string strMeridiem = "a";
if (dwHour > 12)
{
strMeridiem = "p";
dwHour -= 12;
}
return string.Format("{0:0000}-{1:00}-{2:00} {3:00}:{4:00}{5}", dt.Year, dt.Month, dt.Day, dwHour, dt.Minute, strMeridiem);
}
public static void CompressFile(string strPath)
{
strPath = strPath.Replace(",IMPORTANT", "");
lblRetry:
FileStream fh = null;
try
{
fh = new FileStream(strPath, FileMode.Open, FileAccess.Read, FileShare.Read);
}
catch
{
if (DialogResult.Retry != MessageBox.Show("File " + strPath + " could not be compressed: access was denied, or the file does not exist.", "Compression error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error))
{
return;
}
else
{
goto lblRetry;
}
}
byte[] buffer = new byte[fh.Length];
try
{
if (fh.Read(buffer, 0, buffer.Length) != buffer.Length)
{
if (DialogResult.Retry != MessageBox.Show("File " + strPath + " could not be compressed: failed to read the entire file.", "Compression error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error))
{
return;
}
else
{
goto lblRetry;
}
}
}
finally
{
fh.Close();
}
MemoryStream hmsInitialStream = new MemoryStream();
GZipStream gzh = new GZipStream(hmsInitialStream, CompressionMode.Compress, true);
gzh.Write(buffer, 0, buffer.Length);
gzh.Close();
hmsInitialStream.Position = 0;
byte[] @out = new byte[hmsInitialStream.Length];
hmsInitialStream.Read(@out, 0, @out.Length);
hmsInitialStream.Close();
lblRetryVerify:
try
{
if (!Core.VerifyDirectories("Morpheus\\PatchData\\" + strPath))
{
if (DialogResult.Retry != MessageBox.Show("Could not create directory: Morpheus\\PatchData\\" + Core.GetDirectoryName(strPath), "Compression error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error))
{
return;
}
else
{
goto lblRetryVerify;
}
}
else
{
File.WriteAllBytes("Morpheus\\PatchData\\" + Core.CutPath(strPath) + ".gz", @out);
}
}
catch
{
MessageBox.Show("Test");
}
}
public static bool VerifyDirectories(string strPath)
{
if (Directory.Exists(GetDirectoryName(strPath)))
{
return true;
}
else
{
try
{
strPath = GetDirectoryName(strPath);
string[] dirs = strPath.Split('\\');
string strCurrent = "";
for (int i = 0; i < dirs.Length; i++)
{
strCurrent += dirs[i] + "\\";
Directory.CreateDirectory(strCurrent);
}
return true;
}
catch
{
return false;
}
}
}
public static string GetDirectoryName(string strPath)
{
strPath = Core.CutPath(strPath);
if (strPath.IndexOf('\\') == -1 || strPath == "\\")
{
return ".";
}
else
{
string strTmp = strPath.Substring(0, strPath.LastIndexOf('\\'));
if (strTmp.Trim().Length == 0)
{
return ".";
}
else
{
return strTmp;
}
}
}
public static string CutPath(string strPath)
{
strPath = strPath.Replace('/', '\\');
if (strPath.IndexOf(Environment.CurrentDirectory) != -1)
{
strPath = strPath.Remove(strPath.IndexOf(Environment.CurrentDirectory), Environment.CurrentDirectory.Length);
}
return strPath;
}
public static List<InitialFile> ReadList(string strList)
{
//2009-08-27 06:03p
string[] data = strList.Split('\n');
List<InitialFile> lstRet = new List<InitialFile>();
for (int i = 0; i < data.Length; i++)
{
// Integrity check - sort of o_O
if (data[i].Length < 40 || data[i][4] != '-' || data[i][7] != '-' || data[i][14] != ':' || data[i].ToLower().IndexOf("<dir>") != -1)
{
continue;
}
InitialFile file = new InitialFile()
{
strTimestamp = data[i].Substring(0, "0000-00-00 00:00x".Length),
qwSize = long.Parse(data[i].Substring(18, 20).Trim()),
strPath = data[i].Substring(39).Trim(),
};
lstRet.Add(file);
}
return lstRet;
}
public static string ReverseDateFormat(string p)
{
/* public static string GetDateFormat(DateTime dt)
{
int dwHour = dt.Hour;
string strMeridiem = "a";
if (dwHour > 12)
{
strMeridiem = "p";
dwHour -= 12;
}
return string.Format("{0:0000}-{1:00}-{2:00} {3:00}:{4:00}{5}", dt.Year, dt.Month, dt.Day, dwHour, dt.Minute, strMeridiem);
}*/
string[] data = p.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
string[] date = data[0].Split('-');
string[] time = data[1].Split(':');
if (time[1][2] == 'p')
{
time[0] = (int.Parse(time[0].ToString()) + 12).ToString();
}
return new DateTime(int.Parse(date[0]), int.Parse(date[1]), int.Parse(date[2]), int.Parse(time[0]), int.Parse(time[1].Substring(0, 2)), 0).ToString();
}
}
public class InitialFile
{
public string strPath;
public string strTimestamp;
public long qwSize;
}
}






