コード例 #1
0
        private void OnSave()
        {
            if (data != null && data.IsModified())
            {
                if (fileName == null)
                {
                    SaveFileDialog d = new SaveFileDialog();
                    d.RestoreDirectory = true;
                    if (Properties.Settings.Default.LastDirectory.Length > 0)
                    {
                        d.InitialDirectory = Properties.Settings.Default.LastDirectory;
                    }
                    d.FileName   = (SelectedBookCode + "_" + SelectedLanguageName + fileExtensions).ToLower();
                    d.DefaultExt = fileExtensions;
                    if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        Properties.Settings.Default.LastDirectory = Path.GetDirectoryName(d.FileName);
                        Properties.Settings.Default.Save();
                        fileName = d.FileName;
                    }
                    else
                    {
                        return;
                    }
                }

                data.SetProperty("BookCode", SelectedBookCode);
                data.SetProperty("LanguageName", SelectedLanguageName);
                data.Save(fileName);
            }
        }
コード例 #2
0
 public void OnSave()
 {
     if (fileName != null)
     {
         data.Save(fileName);
     }
 }
コード例 #3
0
        private void SaveDocument(string filePath)
        {
            if (filePath != null)
            {
                MNNotificationCenter.CurrentFileName = filePath;
            }
            else
            {
                filePath = MNNotificationCenter.CurrentFileName;
            }

            RSFileWriter fw;
            string       fileName = filePath;
            MNDocument   doc      = MNNotificationCenter.CurrentDocument;

            using (StreamWriter sw = new StreamWriter(@"d:\LearnToRead\save_book.txt"))
            {
                using (BinaryWriter bw = new BinaryWriter(File.Create(fileName)))
                {
                    fw           = new RSFileWriter(bw);
                    fw.logStream = sw;
                    doc.Book.Save(fw);
                }
            }

            fileName = fileName.Replace(".smb", ".smd");
            using (StreamWriter sw = new StreamWriter(@"d:\LearnToRead\save_data.txt"))
            {
                using (BinaryWriter bw = new BinaryWriter(File.Create(fileName)))
                {
                    fw           = new RSFileWriter(bw);
                    fw.logStream = sw;
                    doc.Data.Save(fw);
                }
            }

            if (doc.DefaultLanguage.IsModified())
            {
                fileName = fileName.Replace(".smd", ".sme");
                using (StreamWriter sw = new StreamWriter(@"d:\LearnToRead\save_lang.txt"))
                {
                    using (BinaryWriter bw = new BinaryWriter(File.Create(fileName)))
                    {
                        fw           = new RSFileWriter(bw);
                        fw.logStream = sw;
                        MNLocalisation loc = doc.DefaultLanguage;
                        loc.SetProperty("BookCode", doc.Book.BookCode);
                        loc.SetProperty("LanguageName", "Default");
                        loc.Save(fw);
                        loc.Modified = false;
                    }
                }
            }

            lastSaved = DateTime.Now;
        }
コード例 #4
0
        private void toolStripMenuItem6_Click(object sender, EventArgs e)
        {
            // create language file from folder
            // we need:
            // - book code
            // - directory path
            DialogGenerateLangFile d = new DialogGenerateLangFile();

            d.SetBookCode(MNNotificationCenter.CurrentDocument.Book.BookCode);
            d.SetBookFileName(MNNotificationCenter.CurrentFileName);

            if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string inDir   = d.GetInputDirectory();
                string outFile = d.GetOutputFileName();

                MNLocalisation file = new MNLocalisation();
                file.SetProperty("BookCode", MNNotificationCenter.CurrentDocument.Book.BookCode);
                file.SetProperty("LanguageName", Path.GetFileName(inDir));

                foreach (string objectFileName in Directory.GetFiles(inDir))
                {
                    string extension = Path.GetExtension(objectFileName);
                    if (extension.Equals(".mp3"))
                    {
                        MNReferencedSound sound = new MNReferencedSound();
                        sound.InitializeWithFile(objectFileName);
                        sound.Name = Path.GetFileNameWithoutExtension(objectFileName);
                        file.Sounds.Add(sound);
                        file.Modified = true;
                    }
                }

                file.Save(outFile);
            }
        }
コード例 #5
0
        private void buttonCreate_Click(object sender, EventArgs e)
        {
            if (textBox2.Text.Trim().Length > 0)
            {
                MNDocument     doc  = MNNotificationCenter.CurrentDocument;
                MNLocalisation data = new MNLocalisation();
                data.SetProperty("BookCode", doc.Book.BookCode);
                data.SetProperty("LanguageName", textBox2.Text.Trim());


                string path     = Path.GetDirectoryName(MNNotificationCenter.CurrentFileName);
                string fileName = Path.Combine(path, string.Format("{0}_{1}.sme", data.GetProperty("BookCode"), data.GetProperty("LanguageCode")));
                data.Save(fileName);

                MNBookLanguage bookLang = new MNBookLanguage();
                bookLang.FilePath     = fileName;
                bookLang.BookCode     = data.GetProperty("BookCode");
                bookLang.LanguageName = data.GetProperty("LanguageName");
                doc.Book.Languages.Add(bookLang);

                mainForm.SetLocalisationData(data);
                mainForm.SetFileName(fileName);
            }
        }
コード例 #6
0
        private static void ProcessCommand(string cmd, string arg)
        {
            string[] p;
            string   fn;

            switch (cmd)
            {
            case "BookCode":
                Doc           = new MNDocument();
                Book          = new MNBookHeader();
                Book.BookCode = arg;
                BookCode      = arg;
                Data          = new MNBookData(Doc);
                break;

            case "BookName":
                Book.BookTitle = arg;
                break;

            case "BookColor":
                string[] rgb = arg.Split(',');
                Book.BookColor = Color.FromArgb(int.Parse(rgb[0]), int.Parse(rgb[1]),
                                                int.Parse(rgb[2]));
                break;

            case "BookIcon":
                Book.BookImage = GetSmallImage(arg);
                break;

            case "Author":
                Book.BookAuthor = arg;
                break;

            case "Copyright":
                Book.BookCopyright = arg;
                break;

            case "Publisher":
                Book.BookPublisher = arg;
                break;

            case "Collection":
                Book.BookCollection = arg;
                break;

            case "ExecuteFile":
                ProcessFile(arg);
                break;

            case "Language":
                Localisation = new MNLocalisation();
                Localisation.SetProperty("BookCode", Book.BookCode);
                Localisation.SetProperty("LanguageName", arg);
                break;

            case "EndLanguage":
                string ln = Localisation.GetProperty("LanguageName");
                if (ln == "Default")
                {
                    fn = BookCode + ".sme";
                }
                else
                {
                    fn = string.Format("{0}_{1}.sme", BookCode, Localisation.GetProperty("LanguageName"));
                }
                string filePath = Path.Combine(OutputDir, fn);
                try
                {
                    File.Delete(filePath);
                }
                catch
                {
                }
                Localisation.Save(filePath);
                Localisation = null;
                break;

            case "AddImage":
                MNReferencedImage img = new MNReferencedImage();
                p             = arg.Split(',');
                img.Name      = p[0];
                img.ImageData = Image.FromFile(p[1]);
                Localisation.Images.Add(img);
                break;

            case "AddSound":
                MNReferencedSound snd = new MNReferencedSound();
                p        = arg.Split(',');
                snd.Name = p[0];
                snd.InitializeWithFile(p[1]);
                Localisation.Sounds.Add(snd);
                break;
            }
        }