private static bool UseMD5(string path) { if (!XLPack.IsFileExist(path)) { return(false); } var position = XLPack.FOpen(path, "r"); var res = XLPack.FUseMD5(position); XLPack.FClose(ref position); return(res); }
private static long GetFileSize(string path) { if (!XLPack.IsFileExist(path)) { return(-1); } long s = 0; var position = XLPack.FOpen(path, "r"); s = XLPack.FSize(position); XLPack.FClose(ref position); return(s); }
private static TreeDictionary.XlFile GetFileStat2(string path) { if (!XLPack.IsFileExist(path)) { return(null); } var position = XLPack.FOpen(path, "r"); var stat2 = new XLPack.pack_stat2(); var res = XLPack.FGetStat(position, ref stat2); XLPack.FClose(ref position); return(res ? new TreeDictionary.XlFile(path, stat2) : null); }
private static bool IsPathExist(string path) { if (XLPack.IsFileExist(path)) { return(true); } var fd = new XLPack.afs_finddata(); var first = XLPack.FindFirst(path, ref fd); var exist = first != -1; XLPack.FindClose(first); return(exist); }
private static bool IsDirectory(string path) { if (XLPack.IsFileExist(path)) { return(false); } var fd = new XLPack.afs_finddata(); var first = XLPack.FindFirst(path, ref fd); var flag = first != -1; XLPack.FindClose(first); return(flag); }
private static string GetFileMD5(string path) { if (!XLPack.IsFileExist(path)) { return(""); } var position = XLPack.FOpen(path, "r"); XLPack.afs_md5_ctx md5info = new XLPack.afs_md5_ctx(); var res = XLPack.FGetMD5(position, ref md5info); XLPack.FClose(ref position); return(res ? BitConverter.ToString(md5info.md5).Replace("-", "").ToLower() : ""); }
private static XLPack.pack_stat_t GetFileStat(string path) { var stat = new XLPack.pack_stat_t(); if (!XLPack.IsFileExist(path)) { return(stat); } var position = XLPack.FOpen(path, "r"); var res = XLPack.FGetStat(position, ref stat); XLPack.FClose(ref position); return(stat); }
private static bool SetFileMD5(string path, string hash) { if (!XLPack.IsFileExist(path)) { return(false); } XLPack.afs_md5_ctx md5info = new XLPack.afs_md5_ctx(); md5info.md5 = StringToByteArray(hash); var position = XLPack.FOpen(path, "r"); // fsetmd5 00001111222233334444555566667777 /master/bin32/zlib1.dll var res = XLPack.FSetMD5(position, ref md5info); XLPack.FClose(ref position); return(res); }
private static bool ReCalculateFileMD5(string path) { if (!XLPack.IsFileExist(path)) { return(false); } var position = XLPack.FOpen(path, "r"); long fileSize = XLPack.FSize(position); const int bufSize = 0x4000; byte[] buffer = new byte[bufSize]; IntPtr bufPtr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0); // TODO: Do this without reading the entire file into memory to calculate the MD5 // Maybe try to use the XLPack.DLL's MD5Init, MD5Update and MD5 Finalize functions ? // Using ChunkedMemoryStream instead of MemoryStream to hopefully avoid outofmemory errors on large files ChunkedMemoryStream ms = new ChunkedMemoryStream(); long readTotalSize = 0; while (readTotalSize < fileSize) { long readSize = fileSize - readTotalSize; if (readSize > bufSize) { readSize = bufSize; } XLPack.FRead(position, bufPtr, readSize); ms.Write(buffer, 0, (int)readSize); // readSize should never be out of int range, so it's safe to cast it readTotalSize += readSize; } XLPack.FClose(ref position); ms.Position = 0; MD5 md5Hash = MD5.Create(); string md5String = GetMd5Hash(md5Hash, ms).Replace("-", "").ToLower(); ms.Dispose(); var res = SetFileMD5(path, md5String); return(res); }
private static List <(string, bool)> GetFiles(string path) { var result = new List <(string, bool)>(); var file = path + "*"; var fd = new XLPack.afs_finddata(); var findHandle = XLPack.FindFirst(file, ref fd); if (findHandle != -1) { do { var fileName = Marshal.PtrToStringAnsi(XLPack.GetFileName(ref fd)); var tempFile = path + fileName; var isDirectory = !XLPack.IsFileExist(tempFile); result.Add((tempFile, isDirectory)); } while (XLPack.FindNext(findHandle, ref fd) != -1); } XLPack.FindClose(findHandle); return(result); }