Пример #1
0
        private bool CheckFormat()
        {
            bool result = false;

            try {
                int fileVer;
                // remove a deprecated features
                if (fFormat == GEDCOMFormat.gf_Native)
                {
                    GDMHeader header = fTree.Header;
                    GDMTag    tag;

                    tag = header.FindTag("_ADVANCED", 0);
                    if (tag != null)
                    {
                        header.DeleteTag("_ADVANCED");
                    }

                    tag = header.FindTag("_EXT_NAME", 0);
                    if (tag != null)
                    {
                        header.DeleteTag("_EXT_NAME");
                    }

                    fileVer = ConvertHelper.ParseInt(header.Source.Version, GKData.APP_FORMAT_DEFVER);
                }
                else
                {
                    fileVer = -1;
                }

                fProgress.ProgressInit(LangMan.LS(LSID.LSID_FormatCheck), 100);
                try {
                    bool xrefValid    = true;
                    bool isExtraneous = (fFormat != GEDCOMFormat.gf_Native);

                    int progress = 0;
                    int num      = fTree.RecordsCount;
                    for (int i = 0; i < num; i++)
                    {
                        GDMRecord rec = fTree[i];
                        CheckRecord(rec, fileVer);

                        if (isExtraneous && xrefValid && !CheckRecordXRef(rec))
                        {
                            xrefValid = false;
                        }

                        int newProgress = (int)Math.Min(100, ((i + 1) * 100.0f) / num);
                        if (progress != newProgress)
                        {
                            progress = newProgress;
                            fProgress.ProgressStep(progress);
                        }
                    }

                    // obsolete: AppHost.StdDialogs.ShowQuestionYN(LangMan.LS(LSID.LSID_IDsCorrectNeed))
                    if (!xrefValid)
                    {
                        ConvertIdentifiers();
                    }

                    fTree.TrimExcess();

                    result = true;
                } finally {
                    fProgress.ProgressDone();
                }
            } catch (Exception ex) {
                Logger.WriteError("GEDCOMChecker.CheckFormat()", ex);
                AppHost.StdDialogs.ShowError(LangMan.LS(LSID.LSID_CheckGedComFailed));
            }

            return(result);
        }
Пример #2
0
        public static bool CheckGEDCOMFormat(GDMTree tree, IBaseContext baseContext, IProgressController pc)
        {
            if (tree == null)
            {
                throw new ArgumentNullException("tree");
            }

            if (baseContext == null)
            {
                throw new ArgumentNullException("baseContext");
            }

            if (pc == null)
            {
                throw new ArgumentNullException("pc");
            }

            bool result = false;

            try {
                GEDCOMFormat format = GEDCOMProvider.GetGEDCOMFormat(tree);
                int          fileVer;
                // remove a deprecated features
                if (format == GEDCOMFormat.gf_Native)
                {
                    GDMHeader header = tree.Header;
                    GDMTag    tag;

                    tag = header.FindTag("_ADVANCED", 0);
                    if (tag != null)
                    {
                        header.DeleteTag("_ADVANCED");
                    }

                    tag = header.FindTag("_EXT_NAME", 0);
                    if (tag != null)
                    {
                        header.DeleteTag("_EXT_NAME");
                    }

                    fileVer = ConvertHelper.ParseInt(header.Source.Version, GKData.APP_FORMAT_DEFVER);
                }
                else
                {
                    fileVer = -1;
                }

                pc.ProgressInit(LangMan.LS(LSID.LSID_FormatCheck), 100);
                try {
                    bool xrefValid    = true;
                    bool isExtraneous = (format != GEDCOMFormat.gf_Native);

                    int progress = 0;
                    int num      = tree.RecordsCount;
                    for (int i = 0; i < num; i++)
                    {
                        GDMRecord rec = tree[i];
                        CheckRecord(baseContext, tree, rec, format, fileVer);

                        if (isExtraneous && xrefValid && !CheckRecordXRef(rec))
                        {
                            xrefValid = false;
                        }

                        int newProgress = (int)Math.Min(100, ((i + 1) * 100.0f) / num);
                        if (progress != newProgress)
                        {
                            progress = newProgress;
                            pc.ProgressStep(progress);
                        }
                    }

                    // obsolete: AppHost.StdDialogs.ShowQuestionYN(LangMan.LS(LSID.LSID_IDsCorrectNeed))
                    if (!xrefValid)
                    {
                        ConvertIdentifiers(tree, pc);
                    }

                    result = true;
                } finally {
                    pc.ProgressDone();
                }
            } catch (Exception ex) {
                Logger.LogWrite("GEDCOMChecker.CheckGEDCOMFormat(): " + ex.Message);
                AppHost.StdDialogs.ShowError(LangMan.LS(LSID.LSID_CheckGedComFailed));
            }

            return(result);
        }