Beispiel #1
0
        public static bool CookExcelFile(string excelPath)
        {
            byte[] excelBuffer = null;
            try
            {
                excelBuffer = File.ReadAllBytes(excelPath);
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
                Console.WriteLine(String.Format("Error reading file {0}", excelPath));
                return(false);
            }

            ExcelFile excelFile = new ExcelFile(excelPath);

            try
            {
                excelFile.ParseCSV(excelBuffer, _fileManager);
            }
            catch (Exception e)
            {
                Console.WriteLine("Critical Error:\n" + e);
                return(false);
            }
            if (excelFile.HasIntegrity == false)
            {
                Console.WriteLine(String.Format("Failed to parse excel file {0}", excelPath));
                return(false);
            }

            Console.WriteLine(String.Format("Cooking {0}", Path.GetFileNameWithoutExtension(excelPath)));
            excelBuffer = excelFile.ToByteArray();
            if (excelBuffer == null)
            {
                Console.WriteLine(String.Format("Failed to serialize excel file {0}", excelFile.StringId));
                return(false);
            }

            String writeToPath = excelPath + ".cooked";

            try
            {
                File.WriteAllBytes(writeToPath, excelBuffer);
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
                Console.WriteLine(String.Format("Failed to write cooked file {0} ", writeToPath));
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public static bool CookStringFile(string stringPath)
        {
            byte[] stringsBuffer = null;
            try
            {
                stringsBuffer = File.ReadAllBytes(stringPath);
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
                Console.WriteLine(String.Format("Error reading file {0}", stringPath));
                return(false);
            }

            StringsFile stringsFile = new StringsFile(stringsBuffer, Path.GetFileName(stringPath).ToUpper());

            if (stringsFile.HasIntegrity == false)
            {
                Console.WriteLine(String.Format("Failed to parse strings file {0}", stringPath));
                return(false);
            }

            Console.WriteLine(String.Format("Cooking {0}", Path.GetFileNameWithoutExtension(stringPath)));
            stringsBuffer = stringsFile.ToByteArray();
            if (stringsBuffer == null)
            {
                Console.WriteLine(String.Format("Failed to serialize strings file {0}", stringsFile.StringId));
                return(false);
            }

            String writeToPath = stringPath + ".cooked";

            try
            {
                File.WriteAllBytes(writeToPath, stringsBuffer);
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
                Console.WriteLine(String.Format("Failed to write cooked file {0} ", writeToPath));
                return(false);
            }

            return(true);
        }
Beispiel #3
0
        public static void CookXmlFile(String xmlPath, FileManager fileManager)
        {
            try
            {
                Console.WriteLine(String.Format("Cooking {0}", Path.GetFileNameWithoutExtension(xmlPath)));

                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(xmlPath);

                XmlCookedFile cookedXmlFile = new XmlCookedFile(fileManager, xmlPath);
                byte[]        xmlCookedData = cookedXmlFile.CookXmlDocument(xmlDocument);
                File.WriteAllBytes(xmlPath + ".cooked", xmlCookedData);
            }
            catch (Exception ex)
            {
                String error = "Error: Failed to cook XML file: " + ex.Message;
                ExceptionLogger.LogException(ex, error);
                Console.WriteLine(error);
            }
        }
Beispiel #4
0
        public static void CookRoomDefinitionFiles(IEnumerable <String> levelRulesFiles)
        {
            foreach (String filePath in levelRulesFiles)
            {
                try
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.Load(filePath);

                    RoomDefinitionFile roomDefinitionFile = new RoomDefinitionFile(filePath);
                    roomDefinitionFile.ParseXmlDocument(xmlDocument);
                    byte[] fileBytes = roomDefinitionFile.ToByteArray();

                    File.WriteAllBytes(filePath.Replace(RoomDefinitionFile.ExtensionDeserialised, RoomDefinitionFile.Extension), fileBytes);
                }
                catch (Exception e)
                {
                    ExceptionLogger.LogException(e);
                    Console.WriteLine(String.Format("Error: Failed to serialize file {0}", filePath));
                }
            }
        }
Beispiel #5
0
        // really should make a base for .drl and .rom
        public static void CookLevelRulesFiles(IEnumerable <String> levelRulesFiles)
        {
            Console.WriteLine("Processing level rules...");
            foreach (String filePath in levelRulesFiles)
            {
                try
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.Load(filePath);

                    LevelRulesFile levelRulesFile = new LevelRulesFile(filePath, null);
                    levelRulesFile.ParseXmlDocument(xmlDocument);
                    byte[] fileBytes = levelRulesFile.ToByteArray();

                    File.WriteAllBytes(filePath.Replace(LevelRulesFile.ExtensionDeserialised, LevelRulesFile.Extension), fileBytes);
                }
                catch (Exception e)
                {
                    ExceptionLogger.LogException(e);
                    Console.WriteLine(String.Format("Error: Failed to serialize file {0}", filePath));
                }
            }
        }
Beispiel #6
0
        private static void _CookExcelFiles(IEnumerable <String> excelFilesToCook)
        {
            Dictionary <String, ExcelFile> excelFiles = new Dictionary <String, ExcelFile>();

            Console.WriteLine("Reading Excel CSV content...");
            foreach (String excelPath in excelFilesToCook)
            {
                Console.Write(Path.GetFileName(excelPath) + "... ");

                byte[] fileBytes;
                try
                {
                    fileBytes = File.ReadAllBytes(excelPath);
                }
                catch (Exception e)
                {
                    ExceptionLogger.LogException(e);

                    Console.WriteLine("\nFailed to read file contents!\nIgnore and Continue? [Y/N]: ");
                    char c = (char)Console.Read();
                    if (c == 'y' || c == 'Y')
                    {
                        continue;
                    }

                    return;
                }

                ExcelFile excelFile = new ExcelFile(excelPath);
                try
                {
                    excelFile.LoadCSV(fileBytes);
                }
                catch (Exception e)
                {
                    ExceptionLogger.LogException(e);

                    Console.WriteLine("\nFailed to load CSV contents!\nIgnore and Continue? [Y/N]: ");
                    char c = (char)Console.Read();
                    if (c == 'y' || c == 'Y')
                    {
                        continue;
                    }

                    return;
                }

                excelFiles.Add(excelFile.StringId, excelFile);
            }

            if (excelFiles.Count == 0)
            {
                return;
            }

            Console.WriteLine("\nProcessing Excel CSV content...");
            foreach (ExcelFile excelFile in excelFiles.Values)
            {
                Console.WriteLine("Cooking " + Path.GetFileName(excelFile.FilePath));

                try
                {
                    excelFile.ParseCSV(_fileManager, excelFiles);
                }
                catch (Exception e)
                {
                    ExceptionLogger.LogException(e);

                    Console.WriteLine("Failed to parse CSV data!\nIgnore and Continue? [Y/N]: ");
                    char c = (char)Console.Read();
                    if (c == 'y' || c == 'Y')
                    {
                        continue;
                    }

                    return;
                }

                if (excelFile.HasIntegrity == false)
                {
                    Console.WriteLine("Failed to parse CSV data!\nIgnore and Continue? [Y/N]: ");
                    char c = (char)Console.Read();
                    if (c == 'y' || c == 'Y')
                    {
                        continue;
                    }

                    return;
                }

                byte[] cookedFileBytes;
                try
                {
                    cookedFileBytes = excelFile.ToByteArray();
                }
                catch (Exception e)
                {
                    ExceptionLogger.LogException(e);

                    Console.WriteLine("Failed to serialise CSV data!\nIgnore and Continue? [Y/N]: ");
                    char c = (char)Console.Read();
                    if (c == 'y' || c == 'Y')
                    {
                        continue;
                    }

                    return;
                }

                if (cookedFileBytes == null)
                {
                    Console.WriteLine("Failed to serialise CSV data!\nIgnore and Continue? [Y/N]: ");
                    char c = (char)Console.Read();
                    if (c == 'y' || c == 'Y')
                    {
                        continue;
                    }

                    return;
                }

                String savePath = excelFile.FilePath.Replace(ExcelFile.ExtensionDeserialised, ExcelFile.Extension);
                try
                {
                    File.WriteAllBytes(savePath, cookedFileBytes);
                }
                catch (Exception e)
                {
                    ExceptionLogger.LogException(e);

                    Console.WriteLine("Failed to write cooked excel file!\nIgnore and Continue? [Y/N]: ");
                    char c = (char)Console.Read();
                    if (c == 'y' || c == 'Y')
                    {
                        continue;
                    }

                    return;
                }
            }
        }
Beispiel #7
0
        public static bool PackDatFile(IEnumerable <String> filesToPack, String outputPath, bool forceCreateNewIndex)
        {
            IndexFile indexFile = null;
            bool      isAppend  = false;

            if (!forceCreateNewIndex && File.Exists(outputPath))
            {
                Console.Write("Hellpack has detected an existing index. Append to previous index? [Y/N]: ");
                char ans = (char)Console.Read();
                if (ans == 'y' || ans == 'Y')
                {
                    indexFile = new IndexFile(outputPath, File.ReadAllBytes(outputPath));
                    isAppend  = true;
                }
            }

            if (indexFile == null)
            {
                indexFile = new IndexFile(outputPath);
            }

            foreach (String filePath in filesToPack)
            {
                DateTime lastModified = File.GetLastWriteTime(filePath);

                // if we're appending, check if we've already added this file by checking the modified time
                if (isAppend)
                {
                    PackFileEntry fileEntry = indexFile.GetFileEntry(filePath);
                    if (fileEntry != null && fileEntry.LastModified == lastModified)
                    {
                        continue;
                    }
                }

                String fileName   = Path.GetFileName(filePath);
                String directory  = Path.GetDirectoryName(filePath);
                int    dataCursor = directory.IndexOf("data");
                directory = directory.Remove(0, dataCursor) + "\\";

                byte[] buffer;
                try
                {
                    buffer = File.ReadAllBytes(filePath);
                }
                catch (Exception ex)
                {
                    ExceptionLogger.LogException(ex);
                    Console.WriteLine(String.Format("Warning: Could not read file {0}", filePath));
                    continue;
                }

                Console.WriteLine("Packing " + directory + fileName);
                if (indexFile.AddFile(directory, fileName, buffer, lastModified) == false)
                {
                    Console.WriteLine("Warning: Failed to add file to index...");
                }
            }

            foreach (PackFile file in _fileManager.IndexFiles)
            {
                file.EndDatAccess();
            }

            string thisPack = Path.GetFileNameWithoutExtension(outputPath);

            byte[] indexBytes = indexFile.ToByteArray();
            Crypt.Encrypt(indexBytes);
            Console.WriteLine("Writing " + thisPack);
            try
            {
                File.WriteAllBytes(outputPath, indexBytes);
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
                Console.WriteLine(String.Format("Fatal error: Could not write index {0}", thisPack));
                return(false);
            }

            Console.WriteLine(String.Format("{0} generation complete.", thisPack));
            return(true);
        }