コード例 #1
0
ファイル: FileHelper.cs プロジェクト: dj0817/YesWeDo
        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());
            }
        }
コード例 #2
0
ファイル: FileHelper.cs プロジェクト: dj0817/YesWeDo
        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);
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
0
ファイル: PrcCrypto.cs プロジェクト: dj0817/YesWeDo
        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);
        }
コード例 #5
0
ファイル: FileHelper.cs プロジェクト: dj0817/YesWeDo
        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);
            }
        }
コード例 #6
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);
            }
        }
コード例 #7
0
ファイル: FileHelper.cs プロジェクト: dj0817/YesWeDo
 public static string ToDefaultBattleExportFolder(string filename)
 {
     return(UiHelper.GetParentFolder(filename));
 }
コード例 #8
0
ファイル: FileHelper.cs プロジェクト: dj0817/YesWeDo
 public static bool IsDefaultFolderDialogPath(string filename)
 {
     return(UiHelper.GetLastFolder(filename).Equals(defaultFileName));
 }