Esempio n. 1
0
        private DialogResult SaveFile(bool saveAs = false)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "Kuriimu Archive (*.kup)|*.kup";
            DialogResult dr = DialogResult.OK;

            if (_file == null || saveAs)
            {
                dr = sfd.ShowDialog();
            }

            if ((_file == null || saveAs) && dr == DialogResult.OK)
            {
                _file = new FileInfo(sfd.FileName);
            }

            if (dr == DialogResult.OK)
            {
                _kup.Save(_file.FullName);
                _kupUser.Save(_file.FullName + ".user");
                _hasChanges = false;
                UpdateForm();
            }

            return(dr);
        }
Esempio n. 2
0
        public SaveResult Save(string filename = "")
        {
            SaveResult result = SaveResult.Success;

            if (filename.Trim() != string.Empty)
            {
                FileInfo = new FileInfo(filename);
            }

            try
            {
                _kup.Save(FileInfo.FullName);
            }
            catch (Exception)
            {
                result = SaveResult.Failure;
            }

            return(result);
        }
Esempio n. 3
0
        private void tsbBatchExportKUP_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            fbd.Description         = "Select the source directory containing text files...";
            fbd.SelectedPath        = Settings.Default.LastBatchDirectory == string.Empty ? Settings.Default.LastDirectory : Settings.Default.LastBatchDirectory;
            fbd.ShowNewFolderButton = false;

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                string path      = fbd.SelectedPath;
                int    fileCount = 0;

                if (Directory.Exists(path))
                {
                    string[] types = _fileAdapters.Select(x => x.Extension.ToLower()).ToArray();

                    List <string> files = new List <string>();
                    foreach (string type in types)
                    {
                        if (type != "*.kup")
                        {
                            string[] subTypes = type.Split(';');
                            foreach (string subType in subTypes)
                            {
                                files.AddRange(Directory.GetFiles(path, subType, SearchOption.AllDirectories));
                            }
                        }
                    }

                    // TODO: Ask how to handle overwrites and backups

                    foreach (string file in files)
                    {
                        if (File.Exists(file))
                        {
                            FileInfo     fi             = new FileInfo(file);
                            IFileAdapter currentAdapter = SelectFileAdapter(file, true);

                            if (currentAdapter != null)
                            {
                                KUP kup = new KUP();

                                currentAdapter.Load(file, true);
                                foreach (IEntry entry in currentAdapter.Entries)
                                {
                                    Entry kEntry = new Entry();
                                    kEntry.Name         = entry.Name;
                                    kEntry.EditedText   = entry.EditedText;
                                    kEntry.OriginalText = entry.OriginalText;
                                    kEntry.MaxLength    = entry.MaxLength;
                                    kup.Entries.Add(kEntry);

                                    if (currentAdapter.EntriesHaveSubEntries)
                                    {
                                        foreach (IEntry sub in entry.SubEntries)
                                        {
                                            Entry kSub = new Entry();
                                            kSub.Name         = sub.Name;
                                            kSub.EditedText   = sub.EditedText;
                                            kSub.OriginalText = sub.OriginalText;
                                            kSub.MaxLength    = sub.MaxLength;
                                            kSub.ParentEntry  = entry;
                                            entry.SubEntries.Add(kSub);
                                        }
                                    }
                                }

                                kup.Save(fi.FullName + ".kup");
                                fileCount++;
                            }
                        }
                    }

                    MessageBox.Show("Batch export completed successfully. " + fileCount + " file(s) succesfully exported.", "Batch Export", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            Settings.Default.LastBatchDirectory = fbd.SelectedPath;
            Settings.Default.Save();
        }
Esempio n. 4
0
        private static int BatchExportKUP(string path, bool browseSubdirectories)
        {
            int fileCount = 0;

            Console.WriteLine(path);
            if (Directory.Exists(path))
            {
                var types = _textAdapters.Select(x => x.Extension.ToLower()).Select(y => y.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)).SelectMany(z => z).Distinct().ToList();

                List <string> files = new List <string>();
                foreach (string type in types)
                {
                    if (type != "*.kup")
                    {
                        files.AddRange(Directory.GetFiles(path, type, browseSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly));
                    }
                }

                // TODO: Ask how to handle overwrites and backups
                //Console.WriteLine("{0}", files[0]);

                foreach (string file in files)
                {
                    if (File.Exists(file))
                    {
                        FileInfo     fi             = new FileInfo(file);
                        ITextAdapter currentAdapter = SelectTextAdapter(_textAdapters, file, true);

                        try
                        {
                            if (currentAdapter != null)
                            {
                                KUP kup = new KUP();

                                currentAdapter.Load(file, true);
                                foreach (TextEntry entry in currentAdapter.Entries)
                                {
                                    Entry kEntry = new Entry();
                                    kEntry.Name         = entry.Name;
                                    kEntry.EditedText   = entry.EditedText;
                                    kEntry.OriginalText = entry.OriginalText;
                                    kEntry.MaxLength    = entry.MaxLength;
                                    kup.Entries.Add(kEntry);

                                    if (currentAdapter.EntriesHaveSubEntries)
                                    {
                                        foreach (TextEntry sub in entry.SubEntries)
                                        {
                                            Entry kSub = new Entry();
                                            kSub.Name         = sub.Name;
                                            kSub.EditedText   = sub.EditedText;
                                            kSub.OriginalText = sub.OriginalText;
                                            kSub.MaxLength    = sub.MaxLength;
                                            kSub.ParentEntry  = entry;
                                            kEntry.SubEntries.Add(kSub);
                                        }
                                    }
                                }

                                kup.Save(fi.FullName + ".kup");
                                fileCount++;
                            }
                        }
                        catch (Exception) { }
                    }
                }

                Console.WriteLine(string.Format("Batch export completed successfully. {0} file(s) succesfully exported.", fileCount));
            }

            return(0);
        }