Subversion Repositories spk

Rev

Rev 309 | Rev 324 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 309 Rev 319
Line 2... Line 2...
2
 
2
 
3
#include "WString.h"
3
#include "WString.h"
4
#include "WStringList.h"
4
#include "WStringList.h"
5
#include "../File_IO.h"
5
#include "../File_IO.h"
6
#include "../DirIO.h"
6
#include "../DirIO.h"
-
 
7
 
-
 
8
#ifdef _WIN32
-
 
9
#include <windows.h>
-
 
10
#include <direct.h>
-
 
11
#include <shlobj.h>
-
 
12
#else
-
 
13
#include <dirent.h> 
-
 
14
#include <sys/types.h> 
-
 
15
#include <sys/param.h> 
-
 
16
#include <sys/stat.h> 
-
 
17
#include <unistd.h> 
-
 
18
#endif
7
 
19
 
8
namespace Utils
20
namespace Utils
9
{
21
{
10
	class CommandLine
22
	class CommandLine
11
	{
23
	{
12
	private:
24
	private:
13
		std::shared_ptr<CFileIO> _file;
25
		std::shared_ptr<CFileIO> _file;
14
		Utils::WStringList _options;
26
		Utils::WStringList		_options;
-
 
27
		CDirIO 					_myDoc;
-
 
28
		CDirIO 					_tempDir;
15
		std::vector<Utils::WString> _args;
29
		std::vector<Utils::WString> _args;
-
 
30
		CPackages				_p;
16
 
31
 
17
	public:
32
	public:
18
		CommandLine(int argc, char* argv[])
33
		CommandLine(int argc, char* argv[])
19
		{
34
		{
20
			_file = std::make_shared<CFileIO>(argv[0]);
35
			_file = std::make_shared<CFileIO>(argv[0]);
Line 49... Line 64...
49
#endif
64
#endif
50
				if (d.empty())
65
				if (d.empty())
51
					d = L"./";
66
					d = L"./";
52
				_file->setDir(d);
67
				_file->setDir(d);
53
			}
68
			}
-
 
69
 
-
 
70
			Utils::WString myDoc = L".";
-
 
71
#ifdef _WIN32
-
 
72
			TCHAR pszPath[MAX_PATH];
-
 
73
			if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, pszPath)))
-
 
74
			{
-
 
75
				myDoc = pszPath;
-
 
76
			}
-
 
77
#endif
-
 
78
			_myDoc.setDir(myDoc);
-
 
79
			_tempDir.setDir(L".");
-
 
80
 
-
 
81
#ifdef _WIN32
-
 
82
			TCHAR szPath[MAX_PATH + 1];
-
 
83
			DWORD result = GetTempPath(MAX_PATH + 1, szPath);
-
 
84
			if (result > 0)
-
 
85
				_tempDir.setDir(szPath);
-
 
86
#endif
-
 
87
 
-
 
88
			_p.startup(L".", _tempDir.dir(), _myDoc.dir());
54
		}
89
		}
55
 
90
 
56
		const std::shared_ptr<CFileIO> file() const
91
		const std::shared_ptr<CFileIO> file() const
57
		{
92
		{
58
			return _file;
93
			return _file;
59
		}
94
		}
60
 
95
 
61
		const Utils::WString& cmdName() const
96
		const Utils::WString& cmdName() const
62
		{
97
		{
63
			return _file->filename();
98
			return _file->filename();
64
		}
99
		}
65
 
100
 
66
		const Utils::WString& cmdDir() const
101
		const Utils::WString& cmdDir() const
67
		{
102
		{
68
			return _file->dir();
103
			return _file->dir();
69
		}
104
		}
-
 
105
 
-
 
106
		const Utils::WString& tempDir() const
-
 
107
		{
-
 
108
			return _tempDir.dir();
-
 
109
		}
-
 
110
 
-
 
111
		const Utils::WString& myDoc() const
-
 
112
		{
-
 
113
			return _myDoc.dir();
-
 
114
		}
70
 
115
 
71
		const Utils::WStringList options() const
116
		const Utils::WStringList options() const
72
		{
117
		{
73
			return _options;
118
			return _options;
74
		}
119
		}
75
 
120
 
76
		const std::vector<Utils::WString>& args() const
121
		const std::vector<Utils::WString>& args() const
77
		{
122
		{
78
			return _args;
123
			return _args;
79
		}
124
		}
80
 
125
 
81
		size_t argCount() const
126
		size_t argCount() const
82
		{
127
		{
83
			return _args.size();
128
			return _args.size();
84
		}
129
		}
85
 
130
 
86
		Utils::WString arg(size_t i) const
131
		Utils::WString arg(size_t i) const
87
		{
132
		{
88
			if(i >= _args.size())
133
			if(i >= _args.size())
89
				return Utils::WString::Null();
134
				return Utils::WString::Null();
90
			return _args[i];
135
			return _args[i];
91
		}
136
		}
92
 
137
 
93
		bool hasSwitch(const Utils::WString& s) const
138
		bool hasSwitch(const Utils::WString& s) const
94
		{
139
		{
95
			return _options.contains(s);
140
			return _options.contains(s);
96
		}
141
		}
97
 
142
 
98
		Utils::WString switchData(const Utils::WString& s) const
143
		Utils::WString switchData(const Utils::WString& s) const
99
		{
144
		{
100
			if (_options.contains(s))
145
			if (_options.contains(s))
101
				return _options[s]->data;
146
				return _options[s]->data;
102
			return Utils::WString::Null();
147
			return Utils::WString::Null();
-
 
148
		}
-
 
149
 
-
 
150
		const CPackages& packages() const
-
 
151
		{
-
 
152
			return _p;
-
 
153
		}
-
 
154
 
-
 
155
		const CDirIO& dirIO() const
-
 
156
		{
-
 
157
			return _file->dirIO();
103
		}
158
		}
104
	};
159
	};
105
}
160
}