public async void CheckForChanges()
        {
            DataContract.FileInfo info = FileInfo;
            //check the fileinfo data
            if (info == null)
            {
                return;
            }
            //If the file exists
            if (!File.Exists(info.Filename))
            {
                return;
            }
            //If the file was modified after the last modification date
            if (File.GetLastWriteTime(info.Filename) <= info.LastModifiedDate)
            {
                return;
            }
            //Then we can show a message
            MessageDialogResult Result = await new ViewModelLocator()
                                         .Main.ShowFileChangedDialog();

            if (Result == MessageDialogResult.Affirmative)
            {
                string oldText            = FocusTreeParser.ParseTreeForCompare(this);
                string newText            = FocusTreeParser.ParseTreeScriptForCompare(info.Filename);
                SideBySideDiffModel model = new SideBySideDiffBuilder(
                    new Differ()).BuildDiffModel(oldText, newText);
                new ViewModelLocator().CodeComparator.DiffModel = model;
                new CompareCode().ShowDialog();
            }
        }
Пример #2
0
        private void TestParseAllTrees()
        {
            //Arrange
            Script tester = new Script();

            foreach (string file in Directory.EnumerateFiles("national_focus", "*.txt"))
            {
                string contents = File.ReadAllText(file);
                //Act
                FocusGridModel           model     = FocusTreeParser.CreateTreeFromScript(file, contents);
                FociGridContainer        container = new FociGridContainer(model);
                List <FociGridContainer> list      = new List <FociGridContainer> {
                    container
                };
                Dictionary <string, string> files = FocusTreeParser.ParseAllTrees(list);
                string filecontent = files.FirstOrDefault().Value;
                string fileName    = files.FirstOrDefault().Key;
                //Assert
                Assert.IsNotNull(model);
                Assert.IsTrue(model.FociList.Any());
                Assert.IsNotNull(fileName);
                Assert.IsNotNull(filecontent);
                tester.Analyse(filecontent);
                Assert.IsFalse(tester.Logger.hasErrors());
            }
        }
Пример #3
0
        public void ExportProject(string paramFilename)
        {
            string path = paramFilename + FOCUS_TREE_PATH;

            Directory.CreateDirectory(path);
            //For each parsed focus trees
            foreach (KeyValuePair <string, string> item in
                     FocusTreeParser.ParseAllTrees(fociContainerList))
            {
                using (TextWriter tw = new StreamWriter(path + item.Key + ".txt"))
                {
                    tw.Write(item.Value);
                }
            }
            path = paramFilename + LOCALISATION_PATH;
            Directory.CreateDirectory(Path.GetDirectoryName(path));
            LocalisationContainer loct = null;

            //For each parsed localisation files
            foreach (KeyValuePair <string, string> item in
                     LocalisationParser.ParseEverything(localisationList))
            {
                //localisationList.IndexOf(loct, 0);
                //fork
                //fixed localization files save in UTF-8 with BOM format
                loct = localisationList[0];
                using (Stream stream = File.OpenWrite(path + item.Key + "_" + loct.LanguageName + ".yml")) //save in file name eg.'test_l_english.yml'
                    using (TextWriter tw = new StreamWriter(stream, new UTF8Encoding(true)))
                    {
                        tw.Write(item.Value);
                    }
            }
            path = paramFilename + EVENTS_PATH;
            Directory.CreateDirectory(Path.GetDirectoryName(path));
            //For each parsed event file
            foreach (KeyValuePair <string, string> item in
                     EventParser.ParseAllEvents(eventList))
            {
                //using (TextWriter tw = new StreamWriter(path + item.Key + ".txt"))
                //fork need to be UTF-8 with BOM
                using (TextWriter tw = new StreamWriter(path + item.Key + ".txt", false, new UTF8Encoding(true)))
                {
                    tw.Write(item.Value);
                }
            }
            //For each parsed script file
            foreach (KeyValuePair <string, string> item in
                     ScriptParser.ParseEverything(scriptList))
            {
                using (TextWriter tw = new StreamWriter(paramFilename + "\\" + item.Key + ".txt"))
                {
                    tw.Write(item.Value);
                }
            }
        }
Пример #4
0
        private FocusGridModel TestScriptToTree()
        {
            //Act
            FocusGridModel model = FocusTreeParser.CreateTreeFromScript("usa.txt", File.ReadAllText("usa.txt"));

            //Assert
            Assert.IsNotNull(model);
            Assert.IsTrue(model.FociList.Any());
            Assert.AreEqual(model.TAG, "USA");
            Assert.AreEqual(model.VisibleName, "usa_focus");
            return(model);
        }
Пример #5
0
        public void ExportProject(string paramFilename)
        {
            string path = paramFilename + FOCUS_TREE_PATH;

            Directory.CreateDirectory(path);
            //For each parsed focus trees
            foreach (KeyValuePair <string, string> item in
                     FocusTreeParser.ParseAllTrees(fociContainerList))
            {
                using (TextWriter tw = new StreamWriter(path + item.Key + ".txt"))
                {
                    tw.Write(item.Value);
                }
            }
            path = paramFilename + LOCALISATION_PATH;
            Directory.CreateDirectory(Path.GetDirectoryName(path));
            //For each parsed localisation files
            foreach (KeyValuePair <string, string> item in
                     LocalisationParser.ParseEverything(localisationList))
            {
                using (Stream stream = File.OpenWrite(path + item.Key + ".yml"))
                    using (TextWriter tw = new StreamWriter(stream, new UTF8Encoding()))
                    {
                        tw.Write(item.Value);
                    }
            }
            path = paramFilename + EVENTS_PATH;
            Directory.CreateDirectory(Path.GetDirectoryName(path));
            //For each parsed event file
            foreach (KeyValuePair <string, string> item in
                     EventParser.ParseAllEvents(eventList))
            {
                using (TextWriter tw = new StreamWriter(path + item.Key + ".txt"))
                {
                    tw.Write(item.Value);
                }
            }
            //For each parsed script file
            foreach (KeyValuePair <string, string> item in
                     ScriptParser.ParseEverything(scriptList))
            {
                using (TextWriter tw = new StreamWriter(paramFilename + "\\" + item.Key + ".txt"))
                {
                    tw.Write(item.Value);
                }
            }
        }
        public void ExportProject()
        {
            var dialog = new CommonOpenFileDialog();
            ResourceDictionary resourceLocalization = new ResourceDictionary();

            resourceLocalization.Source = new Uri(Configurator.getLanguageFile(), UriKind.Relative);
            dialog.Title                     = resourceLocalization["Project_Export"] as string;
            dialog.IsFolderPicker            = true;
            dialog.InitialDirectory          = "C:";
            dialog.AddToMostRecentlyUsedList = false;
            dialog.AllowNonFileSystemItems   = false;
            dialog.DefaultDirectory          = "C:";
            dialog.EnsureFileExists          = true;
            dialog.EnsurePathExists          = true;
            dialog.EnsureReadOnly            = false;
            dialog.EnsureValidNames          = true;
            dialog.Multiselect               = false;
            if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                //For each parsed focus trees
                foreach (KeyValuePair <string, string> item in
                         FocusTreeParser.ParseAllTrees(project.fociContainerList))
                {
                    using (TextWriter tw = new StreamWriter(dialog.FileName + "\\" + item.Key + ".txt"))
                    {
                        tw.Write(item.Value);
                    }
                }
                //For each parsed localisation files
                foreach (KeyValuePair <string, string> item in
                         LocalisationParser.ParseEverything(project.localisationList))
                {
                    using (TextWriter tw = new StreamWriter(dialog.FileName + "\\" + item.Key + ".yaml"))
                    {
                        tw.Write(item.Value);
                    }
                }
                //TODO: For each parsed event
            }
        }
Пример #7
0
        private void TestTreeToScript(FocusGridModel model)
        {
            //Arrange
            FociGridContainer        container = new FociGridContainer(model);
            List <FociGridContainer> list      = new List <FociGridContainer> {
                container
            };
            Script tester = new Script();
            //Act
            Dictionary <string, string> files = FocusTreeParser.ParseAllTrees(list);
            string filecontent = files.FirstOrDefault().Value;
            string fileName    = files.FirstOrDefault().Key;

            //Assert
            Assert.IsNotNull(filecontent);
            Assert.IsNotNull(fileName);
            Assert.AreEqual(fileName, "usa_focus");
            //Test if we can process the script
            tester.Analyse(filecontent);
            Assert.IsFalse(tester.Logger.hasErrors());
            Assert.IsNotNull(tester.FindAssignation("tag"));
        }
Пример #8
0
        private void AddFile(string param)
        {
            var dialog = new CommonOpenFileDialog();
            ResourceDictionary resourceLocalization = new ResourceDictionary();

            resourceLocalization.Source = new Uri(Configurator.getLanguageFile(), UriKind.Relative);
            dialog.Title                     = resourceLocalization["Add_Game_File"] as string;
            dialog.InitialDirectory          = Configurator.getGamePath();
            dialog.AddToMostRecentlyUsedList = false;
            dialog.AllowNonFileSystemItems   = false;
            dialog.DefaultDirectory          = "C:";
            dialog.EnsureFileExists          = true;
            dialog.EnsurePathExists          = true;
            dialog.EnsureReadOnly            = false;
            dialog.EnsureValidNames          = true;
            dialog.Multiselect               = false;
            if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                switch (param)
                {
                case "FocusTree":
                {
                    Script script = new Script();
                    script.Analyse(File.ReadAllText(dialog.FileName));
                    fociContainerList.Add(FocusTreeParser.CreateTreeFromScript(dialog.FileName, script));
                    RaisePropertyChanged("fociContainerList");
                    break;
                }

                case "Localisation":
                {
                    localisationList.Add(LocalisationParser.CreateLocaleFromFile(dialog.FileName));
                    RaisePropertyChanged("fociContainerList");
                    break;
                }
                }
            }
        }