DCL 4.0
Loading...
Searching...
No Matches
mediatag/main.cpp
Go to the documentation of this file.
1#include <dcl/Config.h>
2
3#if __DCL_WINDOWS
4#include <windows.h>
5#endif
6
7#include <locale.h>
8#include <stdio.h>
9#include <wchar.h> // wprintf
10
11#include <dcl/Charset.h>
12#include <dcl/Array.h>
13#include <dcl/DateTime.h>
14#include <dcl/FileWriter.h>
15#include <dcl/Files.h>
16#include <dcl/Arguments.h>
17
18#include "MediaInfo.h"
19
20#include "main.h"
21#include "TagCounter.h"
22#include "TagReader.h"
23
24#if __DCL_DEBUG
25#undef __THIS_FILE__
26static const char_t __THIS_FILE__[] = __T("media/main.cpp");
27#endif
28
29__DCL_BEGIN_NAMESPACE
30
31static Arguments::Option __options__[] =
32{
33 { L"summary", L's', NULL, 0, L"Summary of tag items" },
34 { L"verbose", L'v', NULL, 0, L"Produce verbose output" },
35 { NULL, 0, NULL, 0, L"The following options should be grouped together:" },
36 { L"database", L'd', L"STRING", 0, L"Database connection."
37 "\n\t\t\t DRIVER=DCLFirebird;USER=MT100;PASSWORD=pass;SERVER=g02u24kn2/32055;DATABASE=MT100"
38 "\n\t\t\t DRIVER=DCLInformix;USER=MT100;PASSWORD=pass;SERVER=informix02;DATABASE=MT100"
39 "\n\t\t\t DRIVER=DCLMariaDB; USER=MT100;PASSWORD=pass;SERVER=g02u24kn2;PORT=32011;DATABASE=MT100"
40 "\n\t\t\t DRIVER=DCLOracleDb;USER=MT100;PASSWORD=pass;DATABASE=g01r08od21:1521/AL32UTF8"
41 "\n\t\t\t DRIVER=DCLPostgreSQL;USER=MT100;PASSWORD=pass;DATABASE=tcp:postgresql://g02u24kn2:32017/MT100" },
42 { L"dry-run", L'n', NULL, 0, L"perform a trial run with no changes made" },
43 { NULL }
44};
45
47 : Arguments(
48 _output, _errout,
49 L"mediatag 1.0",
50 L"daejung@gowoonsoft.com",
51 L"PATH",
52 L"Collects mp3 tags",
53 __options__
54 )
55{
56 __dryrun = __verbose = __summary = false;
57}
58
59String MainArguments::toString() const
60{
61 StringBuilder sb;
62 sb.append(value0())
63 .append(L" --verbose=").append(String::valueOf(__verbose))
64 .append(L" --summary=").append(String::valueOf(__summary))
65 .append(L" --database=").append(__database)
66 .append(L" --dry-run=").append(String::valueOf(__dryrun))
67 .append(L" values[").append(values().toString())
68 .append(L"]");
69
70 return sb;
71}
72
73void MainArguments::onOption(int _key, const String& _arg)
75{
76 switch (_key) {
77 case L's':
78 __summary = true;
79 break;
80 case L'v':
81 __verbose = true;
82 break;
83 case L'd':
84 __database = _arg;
85 break;
86 case L'n':
87 __dryrun = true;
88 break;
89 }
90}
91
93{
94 return Arguments::onValidate();
95}
96
97void __main(const MainArguments& _args)
98{
99 __DCL_ASSERT(!_args.values().isEmpty());
100 String path = _args.values()[0];
101 if (_args.summary()) {
102 TagCounter counter;
103 if (Files::isDirectory(path)) {
104 TagCounter::readDir(path, counter, _args);
105 }
106 else {
107 TagCounter::read(path, counter);
108 }
109
110 _args.output() << L"[" << path << L"] " << counter.toString() << endl;
111 return;
112 }
113
114 TagReader reader(_args);
115 if (Files::isDirectory(path)) {
116 reader.readDir(path);
117 }
118 else {
119 reader.read(Files::dirname(path), Files::basename(path));
120 }
121}
122
123__DCL_END_NAMESPACE
124
125__DCL_USING_NAMESPACE
126
127int main(int argc, char* argv[])
128{
129 // std::locale::global(std::locale(""));
130 setlocale(LC_ALL, "");
131
133 try {
136#if __DCL_DEBUG
137 DCLDebugSetGlobalReport(&errout);
138#endif
139 MainArguments args(output, errout);
140 if (args.parse(argc, argv)) {
141 String sep(L'=', 80);
142 output << L"Start [" << DateTime::getCurrentLocalTime().toString()
143 << L"]" << endl;
144 if (args.verbose()) {
145 output << L" [" << args.toString() << L"]" << endl;
146 }
147 output << sep << endl;
148
150 try {
151 __main(args);
152 }
153 catch (Exception* e) {
154 errout << e->toStringAll() << endl;
155 e->destroy();
156 }
158
159 output << sep << endl
160 << L"Finish [" << DateTime::getCurrentLocalTime().toString()
161 << L"]" << endl;
162 }
163#if __DCL_DEBUG
164#if __DCL_HAVE_ALLOC_DEBUG
165 DCLDebugDumpGlobalMemoryLeak(DCL_ALLOC_DUMP_ALL, &errout);
166#endif
167 DCLDebugSetGlobalReport(NULL);
168#endif // __DCL_DEBUG
169 }
170 catch(Exception* e) {
171 String s = e->toStringAll();
172 e->destroy();
173 fwprintf(stderr, L"Warning!! Final Exception: %ls\n", s.data());
174 }
176
177 return 0;
178}
#define __THIS_FILE__
Definition _trace.h:14
#define NULL
Definition Config.h:340
wchar_t char_t
Definition Config.h:275
#define __DCL_THROWS1(e)
Definition Config.h:167
#define STDOUT_HANDLE
Definition File.h:55
#define STDERR_HANDLE
Definition File.h:56
#define __DCL_CLEANUP
Definition Object.h:269
#define __DCL_ASSERT(expr)
Definition Object.h:371
#define __T(str)
Definition Object.h:44
#define __DCL_INITIALIZE
Definition Object.h:268
#define endl
virtual String onValidate()
Definition Arguments.cpp:49
String toString() const
Definition DateTime.cpp:826
static DateTime getCurrentLocalTime()
Definition DateTime.cpp:937
virtual void destroy()
Definition Exception.cpp:74
String toStringAll() const
Definition Exception.cpp:45
static String dirname(const String &_path)
Definition Files.cpp:269
static String basename(const String &_path)
Definition Files.cpp:253
static bool isDirectory(const String &_path)
Definition Files.cpp:116
MainArguments(Writer &_output, Writer &_errout)
bool verbose() const
virtual String onValidate()
bool summary() const
virtual void onOption(int _key, const String &_arg) __DCL_THROWS1(Exception *)
virtual String toString() const
static void cleanup()
Definition MediaInfo.cpp:55
static void initialize() __DCL_THROWS1(DllException *)
Definition MediaInfo.cpp:39
static void read(const String &_filename, TagCounter &_counter)
String toString() const
Definition TagCounter.h:28
static void readDir(const String &_path, TagCounter &_counter, const MainArguments &_args)
void read(const String &_dirname, const String &_filename)
void readDir(const String &_path)
__DCL_END_NAMESPACE __DCL_USING_NAMESPACE int main(int argc, char *argv[])
void __main(const MainArguments &_args)