Exemplo n.º 1
0
        private void LoadProperties()
        {
            string recoveryFile;

            try
            {
                recoveryFile = AtomicIO.AtomicRead(RecoveryPath);
            }
            catch (AtomicException)
            {
                System.Diagnostics.Debug.WriteLine("AtomicException when loading QuizRecoveryItem at LoadProperties()");
#warning test if this dispose works as intended (the QuizRecoveryItem should be removed)
                Dispose();
                return;
            }

            var recovery = JsonConvert.DeserializeObject <QuizRecoveryData>(recoveryFile);

            QuizPath = recovery.QuizPath;
            Date     = recovery.LastUpdated;

            lbl_recoveryPath.Text = $"Recovery path: {RecoveryPath}";
            lbl_quizPath.Text     = $"Quiz path: {QuizPath}";
            lbl_date.Text         = $"Auto-recovery-save date: {Date.ToString("yyyy-MM-dd HH:mm:ss")}";
        }
Exemplo n.º 2
0
        private void btn_load_Click(object sender, EventArgs e)
        {
            string recoveryFile;

            try
            {
                recoveryFile = AtomicIO.AtomicRead(RecoveryPath);
            }
            catch (AtomicException ex)
            {
                MessageBox.Show("Could not load recovery file:\r\n\r\n" + ex.ToString(), "SteelQuiz", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            var recovery = JsonConvert.DeserializeObject <QuizRecoveryData>(recoveryFile);

            ((QuizRecovery)Parent.Parent).QuizRecoveryData = recovery;
            ((QuizRecovery)Parent.Parent).DialogResult     = DialogResult.OK;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Finds the quiz path, even when the quiz has been moved to a different location in a quiz folder.
        /// </summary>
        /// <returns>Returns the path of the quiz. Returns null if it can't be found.</returns>
        public string FindQuizPath()
        {
            if (File.Exists(LastKnownPath))
            {
                Quiz quiz = JsonConvert.DeserializeObject <Quiz>(AtomicIO.AtomicRead(LastKnownPath));
                if (quiz.GUID == QuizGuid)
                {
                    // QuizPath is correct
                    return(LastKnownPath);
                }
            }


            // QuizPath is incorrect
            var quizNotFound = new QuizNotFound(QuizGuid, LastKnownPath);

            if (quizNotFound.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                LastKnownPath = quizNotFound.NewQuizPath;
                return(LastKnownPath);
            }

            return(null);
        }
Exemplo n.º 4
0
        public void LoadQuiz(Quiz quiz = null, string quizPath = null, bool fromRecovery = false)
        {
            if (ChangedSinceLastSave)
            {
                //var msg = MessageBox.Show("You have unsaved changes. Save before loading a new quiz?", "SteelQuiz", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                var saveDontSave = new SaveDontSave(this, SystemIcons.Warning, true, "The project contains unsaved changes. Save before loading a new quiz?",
                                                    "Save before loading new quiz? - SteelQuiz");
                saveDontSave.ShowDialog();
                if (saveDontSave.SaveDialogResult == SaveDontSave.SaveResult.Save)
                {
                    if (!SaveQuiz())
                    {
                        return;
                    }
                }
                else if (saveDontSave.SaveDialogResult == SaveDontSave.SaveResult.Cancel)
                {
                    return;
                }
            }

            if (!fromRecovery)
            {
                DeleteRecovery();
            }

            if (quiz == null)
            {
                //ofd_quiz.InitialDirectory = ConfigManager.Config.SyncConfig.QuizFolders[0];
                var ofd = ofd_quiz.ShowDialog();
                if (ofd == DialogResult.OK)
                {
                    QuizPath = ofd_quiz.FileName;
                }
                else
                {
                    return;
                }

                try
                {
                    quiz = JsonConvert.DeserializeObject <Quiz>(AtomicIO.AtomicRead(QuizPath));
                }
                catch (AtomicException ex)
                {
                    // Should never be reached as path exists
                    throw ex;
                }
            }

            if (quizPath != null)
            {
                QuizPath = quizPath;
            }

            UpdateUndoRedoStacks = false;

            SetCards(quiz.Cards.Count + 2);

            QuizGuid       = quiz.GUID;
            cmb_lang1.Text = quiz.CardFrontType;
            cmb_lang2.Text = quiz.CardBackType;

            for (int i = 0; i < quiz.Cards.Count; ++i)
            {
                var ctrl = flp_cards.Controls.OfType <QuizEditorCard>().ElementAt(i);
                var card = quiz.Cards[i];

                ctrl.Guid                 = card.Guid;
                ctrl.txt_front.Text       = card.Front;
                ctrl.FrontSynonyms        = card.FrontSynonyms;
                ctrl.txt_back.Text        = card.Back;
                ctrl.BackSynonyms         = card.BackSynonyms;
                ctrl.ComparisonRules.Data = (StringComp.Rules)FixEnum(card.SmartComparisonRules);
            }

            if (!fromRecovery)
            {
                QuizRecoveryData     = new QuizRecoveryData(QuizPath);
                ChangedSinceLastSave = false;
            }

            UndoStack.Clear();
            RedoStack.Clear();
            UpdateUndoRedoStacks = true;

            SetGlobalSmartComparisonState();
        }