Example #1
0
        public static void CopyFilesWithRegexMatch(IEnumerable <FileInfo> files, string dest)
        {
            StringBuilder errorMessage = new StringBuilder();

            foreach (var file in files)
            {
                var definedLocation = GetFilePathFromLikeName(file.Name);
                if (!String.IsNullOrWhiteSpace(definedLocation))
                {
                    var name = file.Name;
                    if (file.Name.Contains(Defs.FILE_PATCH_PATTERN))
                    {
                        foreach (var replacement in Defs.fileNameReplacements)
                        {
                            definedLocation = definedLocation.Replace(replacement.Item1, replacement.Item2);
                        }
                        name = name.Replace(Defs.FILE_PATCH_PATTERN, "");
                    }
                    errorMessage.Append(CopyFile(file, dest + definedLocation, name));
                }
            }

            if (!String.IsNullOrWhiteSpace(errorMessage.ToString()))
            {
                UiHelper.PopUpMessage(errorMessage.ToString());
            }
        }
Example #2
0
        public XmlDocument DisassembleEncrypted(string fileLocation, string labelsFileLocation = "")
        {
            labelName = labelsFileLocation;

            if (!string.IsNullOrEmpty(labelName))
            {
                try
                {
                    if (hashToStringLabels == null)
                    {
                        hashToStringLabels = LabelIO.GetHashStringDict(labelName);
                    }
                }
                catch (Exception ex)
                {
                    UiHelper.PopUpMessage(ex.Message);
                    return(new XmlDocument());
                }
            }

            file = new ParamFile();
            file.Open(fileLocation);

            xml = new XmlDocument();
            xml.AppendChild(xml.CreateXmlDeclaration("1.0", "UTF-8", null));
            xml.AppendChild(ParamStruct2Node(file.Root));

            return(xml);
        }
Example #3
0
 public static IEnumerable <FileInfo> GetFiles(string file_location)
 {
     try
     {
         return(new DirectoryInfo(file_location).GetFiles());
     }
     catch (Exception ex)
     {
         UiHelper.PopUpMessage(ex.Message);
         return(null);
     }
 }
Example #4
0
 public static XmlReader GetXmlReaderFromStream(Stream stream)
 {
     // Open stream into reader.
     try
     {
         return(XmlReader.Create(stream));
     }
     catch (Exception ex)
     {
         UiHelper.PopUpMessage(ex.Message);
         return(null);
     }
 }
Example #5
0
        public static void CopyFiles(IEnumerable <FileInfo> files, string dest)
        {
            StringBuilder errorMessage = new StringBuilder();

            foreach (var file in files)
            {
                var definedLocation = GetFilePath(file.Name);
                if (!String.IsNullOrWhiteSpace(definedLocation))
                {
                    errorMessage.Append(CopyFile(file, dest + definedLocation, file.Name));
                }
            }

            if (!String.IsNullOrWhiteSpace(errorMessage.ToString()))
            {
                UiHelper.PopUpMessage(errorMessage.ToString());
            }
        }
Example #6
0
        public static void SaveSpiritTitles(IEnumerable <Battle> battles, string fileName)
        {
            MsbtAdapter adapter;
            MsbtAdapter backupAdapter;

            try
            {
                var files = GetFiles(fileName);

                foreach (var file in files.Where(x => Defs.msbtFilesToSave.Contains(x.Name)))
                {
                    var originalSize = file.Length;
                    adapter       = GetLoadedMsbtAdapter(file.FullName);
                    backupAdapter = GetLoadedMsbtAdapter(file.FullName);
                    var updated = false;

                    foreach (var battle in battles.Where(x => x.msbtUpdated))
                    {
                        updated = true;
                        var match = adapter.Entries.FirstOrDefault(x => ((MsbtEntry)x).SpiritBattleId == battle.battle_id);
                        if (match != null)
                        {
                            match.EditedText = battle.combinedMsbtTitle;
                        }
                    }
                    if (updated)
                    {
                        adapter.Save();

                        // See if the file broke.  If so, write the old version back and throw exception.
                        file.Refresh();
                        if (file.Length < originalSize / 2)
                        {
                            backupAdapter.Save();
                            throw new Exception("Error trying to save spirit titles.  Spirit Title changes unsaved.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                UiHelper.PopUpMessage(ex.Message);
            }
        }
Example #7
0
        public static Stream GetStreamFromEncryptedFile(string fileName, string fileLocationLabels)
        {
            var stream = new MemoryStream();

            try
            {
                // Try opening again, and decrypting this time.
                PrcCrypto   encryptedSaver = new PrcCrypto();
                XmlDocument doc            = encryptedSaver.DisassembleEncrypted(fileName, fileLocationLabels);
                doc.Save(stream);
                stream.Position = 0;
                return(stream);
            }
            catch (Exception ex)
            {
                UiHelper.PopUpMessage(ex.Message);
                return(null);
            }
        }
Example #8
0
        public void AssmebleEncrypted(XmlDocument doc, string fileLocation, string labelsFileLocation)
        {
            stringToHashLabels = new OrderedDictionary <string, ulong>();
            if (!string.IsNullOrEmpty(labelsFileLocation))
            {
                try
                {
                    stringToHashLabels = LabelIO.GetStringHashDict(labelsFileLocation);
                }
                catch (Exception ex)
                {
                    UiHelper.PopUpMessage(ex.Message);
                    return;
                }
            }

            file = new ParamFile(Node2ParamStruct(doc.DocumentElement));

            file.Save(fileLocation);
        }
Example #9
0
        public static IEnumerable <FileInfo> GetFilesMatching(string file_location, string match)
        {
            try
            {
                var files      = new DirectoryInfo(file_location).GetFiles();
                var matchFiles = new List <FileInfo>();
                foreach (var file in files)
                {
                    if (SpiritImageMatchesBattle(file, match))
                    {
                        matchFiles.Add(file);
                    }
                }

                return(matchFiles);
            }
            catch (Exception ex)
            {
                UiHelper.PopUpMessage(ex.Message);
                return(null);
            }
        }
Example #10
0
        public static Stream GetStreamFromFile(string fileName)
        {
            // Copy the stream to memory, so we're not holding the resource open.
            MemoryStream stream = new MemoryStream();

            // Open file into stream.
            try
            {
                using (Stream fileStream = new FileStream(fileName, FileMode.Open))
                {
                    fileStream.CopyTo(stream);
                    stream.Position = 0;
                }

                return(stream);
            }
            catch (Exception ex)
            {
                UiHelper.PopUpMessage(ex.Message);
                return(null);
            }
        }