예제 #1
0
        internal static void printDebugLine()
        {
            IntPtr           hCurrScintilla = PluginBase.GetCurrentScintilla();
            ScintillaGateway sci            = new ScintillaGateway(hCurrScintilla);
            var lineNumber       = sci.GetCurrentLineNumber() + 1;
            NotepadPPGateway npp = new NotepadPPGateway();
            var fileName         = Path.GetFileNameWithoutExtension(npp.GetCurrentFilePath());
            var stream           = new FileStream(@"plugins/Config/GoToDefinition/debug_table.txt", FileMode.Open, FileAccess.Read);

            using (var streamReader = new StreamReader(stream, Encoding.UTF8))
            {
                var text = streamReader.ReadToEnd();
                text = text + $"'{fileName}', {lineNumber}, )";
                sci.AddText(text.Length, text);
            }
        }
예제 #2
0
        private static void pmlCommit()
        {
            NotepadPPGateway notepadPPGateway = new NotepadPPGateway();

            //Save the file to original location
            string path = notepadPPGateway.GetCurrentFilePath();

            //check the file is committed file or not.
            if (path.Contains("temp"))
            {
                MessageBox.Show("This file can not be committed. Revert to this version before committing.");
                return;
            }


            //Open Commit form to enter commit message
            CommitWindow commitFrm = new CommitWindow();

            commitFrm.Show();
        }
예제 #3
0
        internal static void myMenuFunction()
        {
            try
            {
                /* Not sure why this works when running as a local admin user but something
                 * fails when running as a user without local admin.  Will investigate later,
                 * for now just accept that previous values may not be retrieved.
                 */
                StringBuilder sbIniFilePath = new StringBuilder(Win32.MAX_PATH);
                Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETPLUGINSCONFIGDIR, Win32.MAX_PATH, sbIniFilePath);
                iniFilePath = sbIniFilePath.ToString();
                if (!Directory.Exists(iniFilePath))
                {
                    Directory.CreateDirectory(iniFilePath);
                }
                iniFilePath = Path.Combine(iniFilePath, PluginName + ".ini");
                StringBuilder savedPathname = new StringBuilder("", 255);
                int           i             = Win32.GetPrivateProfileString("Dependencies", "7ZipExeDirectory", "", savedPathname, 255, iniFilePath);
                config7ZipPath = savedPathname.ToString();
            }
            catch (Exception) { }

            PathTo7Zip = Find7zPath();
            INotepadPPGateway notepad     = new NotepadPPGateway();
            string            currentFile = notepad.GetCurrentFilePath();

            if (string.IsNullOrEmpty(currentFile) || !File.Exists(currentFile))
            {
                MessageBox.Show("Please save the file list first");
                return;
            }
            if (frmMyDlg == null)
            {
                frmMyDlg = new frmMyDlg();
            }
            frmMyDlg.SourceFilePath = currentFile;
            if (frmMyDlg.ShowDialog() == DialogResult.OK)
            {
                CreateArchive(currentFile, frmMyDlg.ArchiveFilename, frmMyDlg.StartDirectory);
            }
        }
예제 #4
0
파일: Main.cs 프로젝트: Jukspa/sptnpp
        internal static void LoadScript()
        {
            try
            {
                using (var socketClient = new SocketClient(Config.AppConfig.Port))
                {
                    socketClient.SendCommand("y_spt_ipc_gamedir");
                    var response = socketClient.GetMessage();

                    if (!response.ContainsKey("path"))
                    {
                        throw new Exception("SPT did not respond with game dir.\n");
                    }

                    var relPath = GetRelativePath(response["path"] + "\\", gateway.GetCurrentFilePath());
                    relPath = Path.ChangeExtension(relPath, null);
                    relPath = relPath.Replace("\\", "/");
                    string scriptCmd;

                    if (Config.AppConfig.ResumeTick > 0)
                    {
                        scriptCmd = string.Format("tas_script_load {0} {1}", relPath, Config.AppConfig.ResumeTick);
                    }
                    else
                    {
                        scriptCmd = string.Format("tas_script_load {0}", relPath);
                    }

                    socketClient.SendCommand(scriptCmd);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(string.Format("Error: {0}", e));
            }
        }
예제 #5
0
 static public bool IsCurrentDocScriptFile(this NotepadPPGateway editor)
 {
     return(editor.GetCurrentFilePath().IsScriptFile());
 }
        public VersionShowWindow()
        {
            InitializeComponent();

            try
            {
                NotepadPPGateway notepadPPGateway = new NotepadPPGateway();

                //Save the file to original location
                string path = notepadPPGateway.GetCurrentFilePath();

                CommitWindow.currentFileDirectory = path;

                //Save the file to another directory
                string currentFileName = System.IO.Path.GetFileName(path);

                allVersionInfo = versionInfo(currentFileName); //All available version info is stored here

                //Now need to add them to UI
                int count = 1;
                foreach (PmlVersion version in allVersionInfo)
                {
                    if (count < 11)
                    {
                        //Finding and assigning filename
                        System.Windows.Controls.Label lblFileName = this.FindName("lblfileName_" + count) as System.Windows.Controls.Label;
                        lblFileName.Content    = version.fileName;
                        lblFileName.Visibility = Visibility.Visible;

                        //Finding and assigning modifiedDate
                        System.Windows.Controls.Label lblModifiedDate = this.FindName("lblfileDate_" + count) as System.Windows.Controls.Label;
                        lblModifiedDate.Content    = version.modifiedDate;
                        lblModifiedDate.Visibility = Visibility.Visible;

                        //Finding and assigning modifiedBy
                        System.Windows.Controls.Label lblModifiedBy = this.FindName("lblModifiedBy_" + count) as System.Windows.Controls.Label;
                        lblModifiedBy.Content    = version.modifiedBy;
                        lblModifiedBy.Visibility = Visibility.Visible;

                        //Finding and assigning commitMessage
                        System.Windows.Controls.RichTextBox lblCommitMessage = this.FindName("lblCommitMessage_" + count) as System.Windows.Controls.RichTextBox;
                        lblCommitMessage.AppendText(version.commitMessage);
                        lblCommitMessage.Visibility = Visibility.Visible;
                    }
                    count++;
                }

                //Finding and assigning count
                System.Windows.Controls.Label lblCountNumber = this.FindName("countNumber") as System.Windows.Controls.Label;
                lblCountNumber.Content    = (count - 1).ToString("00");
                lblCountNumber.Visibility = Visibility.Visible;

                //Search all labels and set horizontal allignement center for version info labels only
                try
                {
                    UIElementCollection uiFileInfoLabels = fileInfoLabels.Children;
                    foreach (System.Windows.Controls.Label lbl in uiFileInfoLabels)
                    {
                        lbl.HorizontalContentAlignment = HorizontalAlignment.Center;
                    }
                }
                catch
                {
                }
            }catch (Exception err)
            {
                MessageBox.Show(err.ToString());
            }
        }
예제 #7
0
        private static void revertToOldVersion()
        {
            try
            {
                string codeDirectory = CommitWindow.codeDirectory;

                NotepadPPGateway notepadPPGateway = new NotepadPPGateway();
                List <string>    linesList        = new List <string>();//all the lines except commit lines

                //Save the file to original location
                string path     = notepadPPGateway.GetCurrentFilePath();
                string savePath = path.Split('\\')[path.Split('\\').Length - 1];//file name
                savePath = savePath.Replace("temp_", "");
                if (!(CommitWindow.currentFileDirectory == "") && Path.GetFileName(CommitWindow.currentFileDirectory) == savePath)
                {
                    //Delete the commit messages from the file
                    //read the file and for original path to save
                    string[] lines = File.ReadAllLines(path);


                    foreach (string line in lines)
                    {
                        if (!(line.Contains("--Commit")))
                        {
                            linesList.Add(line);
                        }
                    }

                    //Getting save directory
                    savePath = CommitWindow.currentFileDirectory;
                }
                else
                {
                    //read the file and for original path to save
                    string[] lines = File.ReadAllLines(path);

                    foreach (string line in lines)
                    {
                        if (line.Contains("--Commit Original Directory: "))
                        {
                            savePath = line.Replace("--Commit Original Directory: ", "");
                            break;
                        }
                    }

                    foreach (string line in lines)
                    {
                        if (!(line.Contains("--Commit")))
                        {
                            linesList.Add(line);
                        }
                    }
                }

                if (!File.Exists(savePath))
                {
                    MessageBox.Show("This file could not be reverted");
                }
                else if (path == savePath)
                {
                    MessageBox.Show("This is the current version");
                }
                else
                {
                    //Save the file without commit message
                    if (File.Exists(savePath))
                    {
                        File.Delete(savePath);
                    }
                    File.WriteAllLines(savePath, linesList);
                    notepadPPGateway.openFile(savePath);
                    MessageBox.Show("Reverted successfully!");
                }
            }catch (Exception err)
            {
                MessageBox.Show(err.ToString());
            }
        }
예제 #8
0
        private void btnCommit_Click(object sender, EventArgs e)
        {
            //Check its pml file or not
            NotepadPPGateway notepadPPGatewayTemp = new NotepadPPGateway();
            string           pathTemp             = notepadPPGatewayTemp.GetCurrentFilePath();
            string           currentFileNameTemp  = Path.GetFileName(pathTemp);
            bool             isPml = Utility.isPml(currentFileNameTemp); //True if this is a PML file



            //Take the commit message
            string[] commitMessage = richTxtCommit.Lines;
            int      i             = 0;

            //Getting commit message
            foreach (string s in commitMessage)
            {
                commitMessage[i] = Utility.commentSpecifier + "Commit Message:$ " + commitMessage[i];

                i++;
            }

            if (!(commitMessage.Length == 0))
            {
                NotepadPPGateway notepadPPGateway = new NotepadPPGateway();

                //Save the file to original location
                string path = notepadPPGateway.GetCurrentFilePath();

                //check the file is committed file or not.
                if (path.Contains("temp"))
                {
                    MessageBox.Show("This file can not be committed. Revert to this version before committing.");
                    return;
                }

                currentFileDirectory = path;//for later use
                notepadPPGateway.SaveCurrentFile();

                //Save the file to another directory
                string   currentFileName = Path.GetFileName(path);
                string   userName        = Environment.UserName;
                DateTime now             = System.DateTime.Now;
                string   pushedFileName  = now.ToString() + "_" + userName + "_" + currentFileName;
                pushedFileName = pushedFileName.Replace(":", "_");
                pushedFileName = pushedFileName.Replace(@"\", "_");
                //Create directory for the original file
                if (Directory.Exists(pushDirectory) && !(pushDirectory == "") && Directory.Exists(rootDirectory) && !(rootDirectory == "") &&
                    Directory.Exists(codeDirectory) && !(codeDirectory == "") && Directory.Exists(finalDirectoryForEncryption) && !(finalDirectoryForEncryption == ""))
                {
                    Directory.CreateDirectory(pushDirectory + "\\" + currentFileName);
                    string pushedFileDirectory = pushDirectory + "\\" + currentFileName + "\\" + pushedFileName;

                    notepadPPGateway.SaveCurrentFile(pushedFileDirectory);

                    //Open the file from remote directory and write commit message on top of it as comment and save

                    AddCommitMessageToFileTop(commitMessage, pushedFileDirectory);

                    MessageBox.Show("Successfully Committed");

                    //Closing the save as file and opening the original file
                    notepadPPGateway.CloseCurrentFile();
                    notepadPPGateway.openFile(path);

                    //Only pml files can be commited as final
                    if ((chkFinal.Checked == true || chkEmergency.Checked == true) && isPml == false)
                    {
                        MessageBox.Show("Only PML file can be committed as Final");
                        return;
                    }


                    if (chkFinal.Checked == true)
                    {
                        //Check file path contains code directory of PML files
                        if (path.Contains(codeDirectory))
                        {
                            string strucDirectory = (path.Replace(codeDirectory, "")).Replace(currentFileName, "");
                            string newDirectory   = finalDirectoryForEncryption + strucDirectory;
                            Directory.CreateDirectory(newDirectory);
                            if (File.Exists(newDirectory + currentFileName))
                            {
                                File.Delete(newDirectory + currentFileName);
                                File.Copy(path, newDirectory + currentFileName);
                            }
                            else
                            {
                                File.Copy(path, newDirectory + currentFileName);
                            }
                        }
                        else
                        {
                            MessageBox.Show("File should be opened from code directory to make as final");
                        }
                    }
                    else if (chkEmergency.Checked == true)
                    {
                        //Check file path contains code directory of PML files
                        if (path.Contains(codeDirectory))
                        {
                            //To copy on final directory for encryption
                            //Same name on same if else conflicts so 'New' added
                            string strucDirectoryNew = (path.Replace(codeDirectory, "")).Replace(currentFileName, "");
                            string newDirectoryNew   = finalDirectoryForEncryption + strucDirectoryNew;
                            if (!Directory.Exists(newDirectoryNew))
                            {
                                Directory.CreateDirectory(newDirectoryNew);
                            }

                            if (File.Exists(newDirectoryNew + currentFileName))
                            {
                                File.Delete(newDirectoryNew + currentFileName);
                                File.Copy(path, newDirectoryNew + currentFileName);
                            }
                            else
                            {
                                File.Copy(path, newDirectoryNew + currentFileName);
                            }


                            //To copy on emergency directory to get immediately

                            newDirectoryNew = emergencyDirectory + strucDirectoryNew;

                            if (!Directory.Exists(newDirectoryNew))
                            {
                                Directory.CreateDirectory(newDirectoryNew);
                            }
                            if (File.Exists(newDirectoryNew + currentFileName))
                            {
                                File.Delete(newDirectoryNew + currentFileName);
                                File.Copy(path, newDirectoryNew + currentFileName);
                            }
                            else
                            {
                                File.Copy(path, newDirectoryNew + currentFileName);
                            }

                            //Utility.pmlindexAppend(emergencyDirectory + "\\" + "pml.index", newDirectoryNew + currentFileName);
                        }
                        else
                        {
                            MessageBox.Show("File should be opened from code directory to make as final");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Invalid Directory");
                }


                //Close the commit form and dispose
                this.Close();
                this.Dispose();
            }
            else
            {
                MessageBox.Show("Write a Commit Message before commiting code describing changes");
            }
        }