Пример #1
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();
        }
Пример #2
0
        private void tsbBatchImportKUP_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            fbd.Description         = "Select the source directory containing text and kup file pairs...";
            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;
                int    importCount = 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));
                            }
                        }
                    }

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

                            if (currentAdapter != null && currentAdapter.CanSave && File.Exists(fi.FullName + ".kup"))
                            {
                                KUP kup = KUP.Load(fi.FullName + ".kup");

                                currentAdapter.Load(file, true);
                                foreach (IEntry entry in currentAdapter.Entries)
                                {
                                    Entry kEntry = kup.Entries.Find(o => o.Name == entry.Name);

                                    if (kEntry != null)
                                    {
                                        entry.EditedText = kEntry.EditedText;
                                    }

                                    if (currentAdapter.EntriesHaveSubEntries && kEntry != null)
                                    {
                                        foreach (IEntry sub in entry.SubEntries)
                                        {
                                            Entry kSub = (Entry)kEntry.SubEntries.Find(o => o.Name == sub.Name);

                                            if (kSub != null)
                                            {
                                                sub.EditedText = kSub.EditedText;
                                            }
                                        }
                                    }
                                }

                                currentAdapter.Save();
                                importCount++;
                            }

                            fileCount++;
                        }
                    }

                    MessageBox.Show("Batch import completed successfully. " + importCount + " of " + fileCount + " files succesfully imported.", "Batch Import", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            Settings.Default.LastBatchDirectory = fbd.SelectedPath;
            Settings.Default.Save();
        }
Пример #3
0
        private void OpenFile(string filename = "")
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.InitialDirectory = Settings.Default.LastDirectory;

            // Supported Types
            ofd.Filter = Tools.LoadFileFilters(_fileAdapters);

            DialogResult dr = DialogResult.OK;

            if (filename == string.Empty)
            {
                dr = ofd.ShowDialog();
            }

            if (dr == DialogResult.OK)
            {
                if (filename == string.Empty)
                {
                    filename = ofd.FileName;
                }

                IFileAdapter _tempAdapter = SelectFileAdapter(filename);

                try
                {
                    if (_tempAdapter != null && _tempAdapter.Load(filename) == LoadResult.Success)
                    {
                        _fileAdapter = _tempAdapter;
                        _fileOpen    = true;
                        _hasChanges  = false;

                        // Select Game Handler
                        foreach (ToolStripItem tsi in tsbGameSelect.DropDownItems)
                        {
                            if (tsi.Text == Settings.Default.SelectedGameHandler)
                            {
                                _gameHandler        = (IGameHandler)tsi.Tag;
                                tsbGameSelect.Text  = tsi.Text;
                                tsbGameSelect.Image = tsi.Image;

                                break;
                            }
                        }
                        if (_gameHandler == null)
                        {
                            _gameHandler = (IGameHandler)tsbGameSelect.DropDownItems[0].Tag;
                        }

                        LoadEntries();
                        UpdateTextView();
                        UpdatePreview();
                        UpdateForm();
                    }

                    Settings.Default.LastDirectory = new FileInfo(filename).DirectoryName;
                    Settings.Default.Save();
                }
                catch (Exception ex)
                {
                    if (_tempAdapter != null)
                    {
                        MessageBox.Show(this, ex.ToString(), _tempAdapter.Name + " - " + _tempAdapter.Description + " Adapter", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(this, ex.ToString(), "Supported Format Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }