Пример #1
0
        private void AddText(string path, bool isFromZip)
        {
            if (!File.Exists(path))
            {
                CloseTab(path);
                return;
            }

            string unformattedText = "";

            if (!isFromZip)
            {
                unformattedText = File.ReadAllText(path);
            }
            else
            {
                if (jet == null)
                {
                    jet = new ZipFile(CurrentProjectVariables.PathToProjectClassFile + "\\" + CurrentProjectVariables.ProjectName + ".jet");
                }

                unformattedText = ProjectHandler.ReadTextFromZipFile(jet, path);
            }

            try
            {
                JToken jt            = JToken.Parse(unformattedText);
                string formattedText = jt.ToString(Formatting.Indented);
                userControls[userControls.Count - 1].Editor_TextBox.Text = formattedText;
            }
            catch (Exception)
            {
                ConsoleHandler.append_CanRepeat("File contains invalid json. Unable to format..");
                userControls[userControls.Count - 1].Editor_TextBox.Text = unformattedText;
            }
        }
Пример #2
0
        private void CheckIfModified(string pathToFile)
        {
            string backupfile = Environment.CurrentDirectory + "\\Backups\\" + CurrentProjectVariables.GameName + "_Original.jet";

            if (!File.Exists(pathToFile) || !File.Exists(backupfile))
            {
                if (JetProps.get().Count <= 0)
                {
                    return;
                }

                if (!File.Exists(pathToFile))
                {
                    ConsoleHandler.append_Force("Can't check if file is modified because the file itself was not found. Was it deleted?");
                }
                else if (!File.Exists(backupfile))
                {
                    ConsoleHandler.append_Force("Can't check if file is modified because the backup was not found");
                }

                return;
            }


            ZipFile backup = new ZipFile(backupfile);

            backup.Password = CurrentProjectVariables.JetPassword;

            string modText      = RemoveWhitespace(File.ReadAllText(pathToFile));
            string pathInZip    = pathToFile.Replace(CurrentProjectVariables.PathToProjectFiles + "\\", "");
            string originalText = RemoveWhitespace(ProjectHandler.ReadTextFromZipFile(backup, pathInZip));

            try
            {
                if (modText == originalText)
                {
                    //file not modded
                    if (CurrentProjectVariables.ModifiedFiles.Contains(pathToFile))
                    {
                        CurrentProjectVariables.ModifiedFiles.Remove(pathToFile);
                    }
                }
                else
                {
                    //file modded
                    if (!CurrentProjectVariables.ModifiedFiles.Contains(pathToFile))
                    {
                        CurrentProjectVariables.ModifiedFiles.Add(pathToFile);
                    }
                }
            }
            catch
            {
                //exception occurred. file probably modded
                if (!CurrentProjectVariables.ModifiedFiles.Contains(pathToFile))
                {
                    CurrentProjectVariables.ModifiedFiles.Add(pathToFile);
                }
            }

            ProjectHandler.SaveProject();
        }