コード例 #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")}";
        }
コード例 #2
0
ファイル: Authenticator.cs プロジェクト: rdebath/MCGalaxy
        static string FindOldHashPath(string name)
        {
            string path = PASS_FOLDER + name + ".dat";

            if (File.Exists(path))
            {
                return(path);
            }

            // Have to fallback on this for case sensitive file systems
            string[] files = AtomicIO.TryGetFiles(PASS_FOLDER, "*.dat");
            if (files == null)
            {
                return(null);
            }

            foreach (string file in files)
            {
                if (file.CaselessEq(path))
                {
                    return(file);
                }
            }
            return(null);
        }
コード例 #3
0
ファイル: CmdReport.cs プロジェクト: rdebath/MCGalaxy
        static void DeleteReport(string user)
        {
            string backup = "extra/reportedbackups/" + user + ".txt";

            AtomicIO.TryDelete(backup);
            File.Move(ReportPath(user), backup);
        }
コード例 #4
0
        public static void AutoloadPlugins()
        {
            string[] files = AtomicIO.TryGetFiles("plugins", "*.dll");

            if (files != null)
            {
                foreach (string path in files)
                {
                    LoadPlugin(path, true);
                }
            }
            else
            {
                Directory.CreateDirectory("plugins");
            }
        }
コード例 #5
0
ファイル: CmdEnvironment.cs プロジェクト: rdebath/MCGalaxy
        static void MessagePresets(Player p)
        {
            p.Message("&T/Env preset [type] &H- Applies an env preset on the map");
            p.Message("&HPresets: &f{0}", EnvPreset.Presets.Join(pr => pr.Key));

            string[] files = AtomicIO.TryGetFiles("presets", "*.env");
            if (files == null)
            {
                return;
            }

            string all = files.Join(f => Path.GetFileNameWithoutExtension(f));

            if (all.Length > 0)
            {
                p.Message("&HCustom presets: &f" + all);
            }
        }
コード例 #6
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;
        }
コード例 #7
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);
        }
コード例 #8
0
ファイル: QuizRecoveryData.cs プロジェクト: steel9/SteelQuiz
 public void Save(Quiz quiz)
 {
     Quiz        = quiz;
     LastUpdated = DateTime.Now;
     AtomicIO.AtomicWrite(RecoveryFilePath, JsonConvert.SerializeObject(this, Formatting.Indented));
 }
コード例 #9
0
        private bool SaveQuiz(bool saveAs = false, string customPath = null)
        {
            string path = null;

            if (customPath == null)
            {
                if (QuizPath == null || saveAs)
                {
                    sfd_quiz.InitialDirectory = ConfigManager.Config.StorageConfig.DefaultQuizSaveFolder;
                    int untitledCounter = 1;
                    path = $"Untitled{ untitledCounter }.steelquiz";
                    while (File.Exists(Path.Combine(QuizCore.QUIZ_FOLDER_DEFAULT, path)))
                    {
                        ++untitledCounter;
                        path = $"Untitled{ untitledCounter }.steelquiz";
                    }

                    var sfd = sfd_quiz.ShowDialog();
                    if (sfd != DialogResult.OK)
                    {
                        return(false);
                    }

                    if (QuizPath != sfd_quiz.FileName)
                    {
                        QuizGuid = Guid.NewGuid(); // create new guid if path is not the same
                    }
                    path = sfd_quiz.FileName;
                }
                else
                {
                    path = QuizPath;
                }
            }
            else
            {
                path = customPath;
            }

            UseWaitCursor = true;

            var quiz = ConstructQuiz();

            AtomicIO.AtomicWrite(path, JsonConvert.SerializeObject(quiz, Formatting.Indented));

            if (customPath == null)
            {
                QuizPath             = path;
                ChangedSinceLastSave = false;
            }

            QuizCore.LoadQuizAccessData();

            QuizCore.QuizIdentities[quiz.GUID]  = new QuizIdentity(quiz.GUID, QuizPath);
            QuizCore.QuizAccessTimes[quiz.GUID] = DateTime.Now;

            QuizCore.SaveQuizAccessData();

            UseWaitCursor = false;

            ShowNotification("Quiz has been saved", 3000);
            return(true);
        }
コード例 #10
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();
        }