コード例 #1
0
        private void OpenFile(string filename = "")
        {
            OpenFileDialog ofd = new OpenFileDialog();

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

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

            if (dr == DialogResult.OK)
            {
                try
                {
                    _file     = new FileInfo(filename);
                    _fileOpen = true;
                    _kup      = KUP.Load(filename);
                    _kupUser  = KupUser.Load(filename + ".user");
                    LoadForm();
                    _hasChanges = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), ex.Message, MessageBoxButtons.OK);
                    _fileOpen   = false;
                    _hasChanges = false;
                }

                UpdateForm();
            }
        }
コード例 #2
0
ファイル: KupAdapter.cs プロジェクト: Moonstriker/Kuriimu
        public bool Identify(string filename)
        {
            bool result = true;

            try
            {
                KUP.Load(filename);
            }
            catch (Exception)
            {
                result = false;
            }

            return(result);
        }
コード例 #3
0
ファイル: KupAdapter.cs プロジェクト: Moonstriker/Kuriimu
        public LoadResult Load(string filename, bool autoBackup = false)
        {
            LoadResult result = LoadResult.Success;

            FileInfo = new FileInfo(filename);

            if (FileInfo.Exists)
            {
                _kup = KUP.Load(FileInfo.FullName);

                foreach (Entry entry in _kup.Entries)
                {
                    entry.PointerCleanup();
                }
            }
            else
            {
                result = LoadResult.FileNotFound;
            }

            return(result);
        }
コード例 #4
0
ファイル: Editor.cs プロジェクト: getov/Kuriimu
        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();
        }
コード例 #5
0
        private static int BatchImportKUP(string path, bool browseSubdirectories)
        {
            int fileCount   = 0;
            int importCount = 0;

            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));
                    }
                }

                foreach (string file in files)
                {
                    if (File.Exists(file))
                    {
                        FileInfo     fi             = new FileInfo(file);
                        ITextAdapter currentAdapter = SelectTextAdapter(_textAdapters, file, true);
                        try
                        {
                            if (currentAdapter != null && currentAdapter.CanSave && File.Exists(fi.FullName + ".kup"))
                            {
                                KUP kup = KUP.Load(fi.FullName + ".kup");

                                currentAdapter.Load(file, true);
                                foreach (TextEntry 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 (TextEntry 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++;
                        }
                        catch (Exception) { }
                    }
                }
                Console.WriteLine(string.Format("Batch import completed successfully. {0} of {1} files succesfully imported.", importCount, fileCount));
            }

            return(0);
        }