1 /*
2  * Part of WCM Commander
3  * https://github.com/corporateshark/WCMCommander
4  * wcm@linderdaum.com
5  */
6 
7 #pragma once
8 
9 #include "fileassociations.h"
10 
11 #ifdef _WIN32
12 
13 #include "w32cons.h"
14 typedef W32Cons TerminalWin_t;
15 
16 #else
17 
18 #include "termwin.h"
19 typedef TerminalWin TerminalWin_t;
20 
21 #endif
22 
23 
24 class NCWin;
25 class StringWin;
26 class NCHistory;
27 class PanelWin;
28 
29 class FS;
30 class FSPath;
31 
32 
33 /// Contains logic for running and opening files
34 class FileExecutor
35 {
36 private:
37 
38 	NCWin* m_NCWin;
39 	StringWin& m_EditPref;
40 	NCHistory& m_History;
41 	TerminalWin_t& m_Terminal;
42 
43 	int m_ExecId;
44 	unicode_t m_ExecSN[64];
45 
46 	FileExecutor( const FileExecutor& ) = delete;
47 	FileExecutor& operator=(const FileExecutor&) = delete;
48 
49 public:
50 	FileExecutor( NCWin* NCWin, StringWin& editPref, NCHistory& history, TerminalWin_t& terminal );
~FileExecutor()51 	virtual ~FileExecutor() {}
52 
53 	/// Shows context menu at the given position for the selected file
54 	void ShowFileContextMenu( cpoint point, PanelWin* Panel );
55 
56 	/// Runs the given command on the given panel
57 	bool StartCommand( const std::vector<unicode_t>& CommandString, PanelWin* Panel, bool ForceNoTerminal, bool ReplaceSpecialChars );
58 
59 	/// Applies the given command to the selected files on the given panel
60 	void ApplyCommand( const std::vector<unicode_t>& cmd, PanelWin* Panel );
61 
62 	/// Starts to execute current file on the given panel using file associations
63 	bool StartFileAssociation( PanelWin* panel, eFileAssociation Mode );
64 
65 	/// Executes selected file when Enter key is pressed
66 	void ExecuteFileByEnter( PanelWin* Panel, bool Shift );
67 
68 	/// Stops current run process in terminal
69 	void StopExecute();
70 
71 	/// Called from main NCWin
72 	void ThreadSignal( int id, int data );
73 
74 	/// Called from main NCWin
75 	void ThreadStopped( int id, void* data );
76 
77 private:
78 	const clNCFileAssociation* FindFileAssociation( const unicode_t* FileName ) const;
79 
80 	/// Starts to execute the given command in the given dir
81 	void StartExecute( const unicode_t* cmd, FS* fs, FSPath& path, bool NoTerminal = false );
82 
83 	bool DoStartExecute( const unicode_t* pref, const unicode_t* cmd, FS* fs, FSPath& path, bool NoTerminal = false );
84 
85 	/// Executes selected runnable file (.exe, .bat, etc.) from the given panel
86 	void ExecuteFile( PanelWin* panel );
87 
88 	bool ProcessCommand_CD( const unicode_t* cmd, PanelWin* Panel );
89 	bool ProcessCommand_CLS( const unicode_t* cmd );
90 	bool ProcessBuiltInCommands( const unicode_t* cmd, PanelWin* Panel );
91 };
92