public static void Main() { string[] commandLineArgs = Environment.GetCommandLineArgs(); DuneImpactor.Print_Welcome(); if (((IEnumerable <string>)commandLineArgs).Count <string>() != 2) { Console.WriteLine("FATAL Error: too much or not enough arguments.\r\n"); DuneImpactor.Print_Help(); } else { string str = commandLineArgs[1].Replace("\"", "").Replace("'", "").Replace("/", "\\"); if ((uint)Operators.CompareString(Conversions.ToString(str.Last <char>()), "\\", false) > 0U) { str += "\\"; } if (Directory.Exists(str)) { DuneImpactor.ImpactDat(str); } else { Console.WriteLine("FATAL ERROR: " + str + " directory not exist !\r\n"); } } Console.WriteLine("\r\nPress Enter to exit."); Console.Read(); }
public static void ImpactDat(string path) { string str1 = ""; string str2 = path.Substring(0, checked (path.Length - 1)); string[] strArray1 = str2.Split('\\'); string str3 = strArray1[checked (strArray1.Length - 1)].ToUpper() + ".DAT"; string folder = str2.Substring(0, str2.LastIndexOf("\\")) + "\\"; Console.WriteLine("[STARTING] Packing of the DatFile has started...\r\n"); string str4 = str1 + "[STARTING] Packing of the DatFile has started...\r\n\r\n"; if (File.Exists(folder + str3)) { File.Delete(folder + str3); } FileStream input1 = new FileStream(folder + str3, FileMode.Create); input1.Seek(0L, SeekOrigin.Begin); DuneImpactor.WritetoFileStream(input1, DuneImpactor.DatFileVersion); Console.WriteLine("[STEP 1] Reading all files and folders...\r\n"); string str5 = str4 + "[STEP 1] Reading all files and folders...\r\n\r\n"; string[] listOfFiles = DuneFiles.ListOfFiles; Console.WriteLine(listOfFiles.Length.ToString() + " files founds...\r\n"); string str6 = str5 + listOfFiles.Length.ToString() + " files founds...\r\n\r\n"; ArrayList arrayList = new ArrayList(); int number = 65536; int num = checked (listOfFiles.Length - 1); int index1 = 0; while (index1 <= num) { listOfFiles[index1] = listOfFiles[index1].Replace(path, ""); if (File.Exists(path + listOfFiles[index1])) { DuneImpactor.DatasSection datasSection2 = new DuneImpactor.DatasSection(); int length = checked ((int)new FileInfo(path + listOfFiles[index1]).Length); byte[] bytes = DuneImpactor.UnicodeStringToBytes(listOfFiles[index1]); datasSection2.NameOfFile = (byte[])DuneImpactor.AddNullBytesUntilEnd(bytes, 16); datasSection2.SizeOfFile = DuneImpactor.UnicodeIntegerToBytes(length); datasSection2.OffsetOfFile = DuneImpactor.UnicodeIntegerToBytes(number); datasSection2.Unused = new byte[1]; arrayList.Add((object)datasSection2); checked { number += length; } } checked { ++index1; } } Console.WriteLine("[STEP 2] Writing the header to the DatFile...\r\n"); string str7 = str6 + "[STEP 2] Writing the header to the DatFile...\r\n\r\n"; foreach (DuneImpactor.DatasSection datasSection2 in arrayList) { DuneImpactor.WritetoFileStream(input1, datasSection2.NameOfFile); DuneImpactor.WritetoFileStream(input1, datasSection2.SizeOfFile); DuneImpactor.WritetoFileStream(input1, datasSection2.OffsetOfFile); DuneImpactor.WritetoFileStream(input1, datasSection2.Unused); } int position = checked ((int)input1.Position); while (position <= (int)ushort.MaxValue) { DuneImpactor.WritetoFileStream(input1, new byte[1]); checked { ++position; } } Console.WriteLine("The header has been successfully written.\r\n"); string str8 = str7 + "The header has been successfully written.\r\n\r\n"; Console.WriteLine("[STEP 3] Writing all files to the DatFile...\r\n"); string str9 = str8 + "[STEP 3] Writing all files to the DatFile...\r\n\r\n"; input1.Close(); string[] strArray2 = listOfFiles; int index2 = 0; while (index2 < strArray2.Length) { string str10 = strArray2[index2]; FileStream input2 = new FileStream(path + str10, FileMode.Open); input2.Seek(0L, SeekOrigin.Begin); DuneImpactor.ReadWritetoFileStream(input2, folder + str3, checked ((uint)input2.Length)); input2.Close(); Console.WriteLine("Writing... " + str10); str9 = str9 + "Writing... " + str10 + "\r\n"; checked { ++index2; } } Console.WriteLine("\r\n[DONE] Packing finished !\r\n"); DuneImpactor.WriteLog(str9 + "\r\n[DONE] Packing finished !\r\n\r\n", folder); }