Example #1
0
        static Manager()
        {
            if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
            {
                return;
            }
            string path = TaxonUtils.GetConfigFilePath();

            if (Directory.Exists(path))
            {
                string[] files  = Directory.GetFiles(path);
                string   prefix = Path.GetFileNameWithoutExtension(TaxonUtils.GetConfigFileName("language_")).ToLower();
                foreach (string f in files)
                {
                    string fname = Path.GetFileNameWithoutExtension(f).ToLower();
                    if (fname.StartsWith(prefix))
                    {
                        fname = fname.Replace(prefix, "");
                        if (fname.Length == 2)
                        {
                            Languages.Add(fname);
                        }
                    }
                }
            }
            Languages.Load();
            Languages.Save();
            CurrentLanguage = Languages.GetDefault();
            IsDirty         = false;
            StartWatcher();
        }
        private void buttonGenerate_Click(object sender, EventArgs e)
        {
            if (!CheckFolder())
            {
                return;
            }

            using (ProgressDialog progressDlg = new ProgressDialog())
            {
                progressDlg.StartPosition = FormStartPosition.CenterScreen;
                progressDlg.Show();

                string folder   = BuildFolder();
                string filename = labelTaxon.Text + ".tol";

                string logFile     = Path.Combine(folder, "generate.log");
                string treeFileTol = Path.Combine(folder, filename);
                string treeFileXml = Path.ChangeExtension(treeFileTol, "xml");

                bool comments   = checkBoxExportComments.Checked;
                bool photos     = checkBoxExportPhotos.Checked;
                bool sounds     = checkBoxExportSounds.Checked;
                bool exe        = checkBoxExe.Checked;
                bool ascendants = checkBoxExportAscendants.Checked;


                using (StreamWriter log = new StreamWriter(logFile))
                {
                    log.WriteLine("Start generate data for ");
                    log.WriteLine("  taxon   : " + _Taxon.Desc.RefMainName);
                    log.WriteLine("  in graph: " + TaxonUtils.MainGraph?.Description);

                    TaxonTreeNode nodeToExport = _Taxon;
                    if (ascendants)
                    {
                        TaxonTreeNode Current = _Taxon;
                        while (Current != null && Current.Father != null)
                        {
                            TaxonTreeNode fatherNode = new TaxonTreeNode();
                            fatherNode.Father = Current.Father.Father;
                            fatherNode.Desc   = Current.Father.Desc;
                            fatherNode.Children.Add(nodeToExport);
                            nodeToExport = fatherNode;
                            Current      = Current.Father;
                        }
                    }

                    ProgressItem piSaveData = progressDlg.Add("Saving main file", null, 0, 3);
                    log.WriteLine("");
                    log.WriteLine("Save tree in " + treeFileXml);
                    TaxonUtils.Save(nodeToExport, treeFileXml);
                    piSaveData.Update(1);
                    log.WriteLine("Save tree in " + treeFileTol);
                    TaxonUtils.Save(nodeToExport, treeFileTol);
                    piSaveData.Update(2);

                    int count = 0;
                    nodeToExport.ParseNode((node) => { count++; });
                    piSaveData.Update(3);
                    piSaveData.End();

                    log.WriteLine("");
                    log.WriteLine("Total nodes    : " + count);
                    log.WriteLine("Export ascendants: " + ascendants);
                    log.WriteLine("Export comments: " + comments);
                    log.WriteLine("Export images  : " + photos);
                    log.WriteLine("Export sounds  : " + sounds);

                    ExportData exportData = new ExportData(TaxonUtils.GetTaxonPath(), folder, log);

                    if (comments)
                    {
                        log.WriteLine("");
                        log.WriteLine("Exporting comments");
                        exportData.ProgressItem = progressDlg.Add("Exporting comments", "", 0, count - 1);
                        nodeToExport.ParseNode((node) => ExportComments(node, exportData));
                        exportData.ProgressItem.End();
                    }

                    if (photos)
                    {
                        log.WriteLine("");
                        log.WriteLine("Exporting photos");
                        exportData.ProgressItem = progressDlg.Add("Exporting photos", "", 0, count - 1);
                        nodeToExport.ParseNodeDesc((desc) => ExportPhotos(desc, exportData));
                        exportData.ProgressItem.End();
                    }

                    if (sounds)
                    {
                        log.WriteLine("");
                        log.WriteLine("Exporting sounds");
                        exportData.ProgressItem = progressDlg.Add("Exporting sounds", "", 0, count - 1);
                        nodeToExport.ParseNodeDesc((desc) => ExportSounds(desc, exportData));
                        exportData.ProgressItem.End();
                    }

                    if (exe)
                    {
                        exportData.ProgressItem = progressDlg.Add("Exporting exe/config", "", 0, 2);
                        string sourceExe = Assembly.GetEntryAssembly().Location;
                        string destExe   = Path.Combine(exportData.NewPath, Path.GetFileName(sourceExe));
                        File.Copy(sourceExe, destExe);
                        exportData.ProgressItem.Update(1);

                        string sourceConfig = TaxonUtils.GetConfigFileName(TaxonUtils.MyConfig.Name);
                        string destConfig   = Path.Combine(exportData.NewPath, "Config", Path.GetFileName(sourceConfig));

                        string saveFileName = TaxonUtils.MyConfig.TaxonFileName;
                        string savePath     = TaxonUtils.MyConfig.TaxonPath;
                        TaxonUtils.MyConfig.TaxonFileName = filename;
                        TaxonUtils.MyConfig.TaxonPath     = folder;
                        TaxonUtils.MyConfig.Save(destConfig, destExe);
                        TaxonUtils.MyConfig.TaxonFileName = saveFileName;
                        TaxonUtils.MyConfig.TaxonPath     = savePath;
                        exportData.ProgressItem.Update(2);
                        exportData.ProgressItem.End();
                    }
                }

                MessageBox.Show("Generate done");
            }
            Close();
        }