DCL 3.7.4
Loading...
Searching...
No Matches
work/mediatag/main.cpp
Go to the documentation of this file.
1#include <dcl/Config.h>
2
3#ifdef __WINNT__
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#include "Version.h"
24
25#if __DCL_HAVE_THIS_FILE__
26#undef __THIS_FILE__
27static const char_t __THIS_FILE__[] = __T("media/main.cpp");
28#endif
29
30__DCL_BEGIN_NAMESPACE
31
32static Arguments::Option __options__[] =
33{
34 { L"summary", L's', NULL, 0, L"Summary of tag items" },
35 { L"verbose", L'v', NULL, 0, L"Produce verbose output" },
36 { NULL, 0, NULL, 0, L"The following options should be grouped together:" },
37 { L"database", L'd', L"STRING", 0, L"Database connection."
38 "\n\t\t\t DRIVER=DCLFirebird;USER=MT100;PASSWORD=pass;SERVER=g02u24kn2/32055;DATABASE=MT100"
39 "\n\t\t\t DRIVER=DCLInformix;USER=MT100;PASSWORD=pass;SERVER=informix02;DATABASE=MT100"
40 "\n\t\t\t DRIVER=DCLInterBase;USER=MT100;PASSWORD=pass;SERVER=n0317ud70p/3050;DATABASE=MT100"
41 "\n\t\t\t DRIVER=DCLMariaDB; USER=MT100;PASSWORD=pass;SERVER=g02u24kn2;PORT=32011;DATABASE=MT100"
42 "\n\t\t\t DRIVER=DCLOracle; USER=MT100;PASSWORD=pass;DATABASE=g01r08od21:1521/AL32UTF8"
43 "\n\t\t\t DRIVER=DCLPostgreSQL;USER=MT100;PASSWORD=pass;SERVER=g02u24kn2;PORT=32017;DATABASE=MT100"
44 "\n\t\t\t DRIVER=DCLSQLCipher; DATABASE=MT100.sqlcipher;KEY=key"
45 "\n\t\t\t DRIVER=DCLSQLite3; DATABASE=MT100.sqlite3"
46 "\n\t\t\t DRIVER={ODBC Driver 18 for SQL Server};Server=g02u24kn2,31433;Database=MT100;UID=MT100;PWD=pass" },
47 { L"dry-run", L'n', NULL, 0, L"perform a trial run with no changes made" },
48 { NULL }
49};
50
52 : Arguments(
53 _output, _errout,
55 L"daejung@gowoonsoft.com",
56 L"PATH",
57 L"Collects mp3 tags",
58 __options__
59 )
60{
61 __dryrun = __verbose = __summary = false;
62}
63
64String MainArguments::toString() const
65{
66 StringBuilder sb;
67 sb.append(value0())
68 .append(L" --verbose=").append(String::valueOf(__verbose))
69 .append(L" --summary=").append(String::valueOf(__summary))
70 .append(L" --database=").append(__database)
71 .append(L" --dry-run=").append(String::valueOf(__dryrun))
72 .append(L" values[").append(values().toString())
73 .append(L"]");
74
75 return sb;
76}
77
78void MainArguments::onOption(int _key, const String& _arg)
80{
81 switch (_key) {
82 case L's':
83 __summary = true;
84 break;
85 case L'v':
86 __verbose = true;
87 break;
88 case L'd':
89 __database = _arg;
90 break;
91 case L'n':
92 __dryrun = true;
93 break;
94 }
95}
96
98{
99 return Arguments::onValidate();
100}
101
102void __main(const MainArguments& _args)
103{
104 __DCL_ASSERT(!_args.values().isEmpty());
105 String path = _args.values()[0];
106 if (_args.summary()) {
107 TagCounter counter;
108 if (Files::isDirectory(path)) {
109 TagCounter::readDir(path, counter, _args);
110 }
111 else {
112 TagCounter::read(path, counter);
113 }
114
115 _args.output() << L"[" << path << L"] " << counter.toString() << endl;
116 return;
117 }
118
119 TagReader reader(_args);
120 if (Files::isDirectory(path)) {
121 reader.readDir(path);
122 }
123 else {
124 reader.read(Files::dirname(path), Files::basename(path));
125 }
126}
127
128__DCL_END_NAMESPACE
129
130__DCL_USING_NAMESPACE
131
132int main(int argc, char* argv[])
133{
134 // std::locale::global(std::locale(""));
135 setlocale(LC_ALL, "");
136
138 try {
141#ifdef __DCL_DEBUG
142 DCLDebugSetGlobalReport(&errout);
143#endif
144 MainArguments args(output, errout);
145 if (args.parse(argc, argv)) {
146 String sep(L'=', 80);
147 output << L"Start [" << DateTime::getCurrentLocalTime().toString()
148 << L"]" << endl;
149 if (args.verbose()) {
150 output << L" [" << args.toString() << L"]" << endl;
151 }
152 output << sep << endl;
153
155 try {
156 __main(args);
157 }
158 catch (Exception* e) {
159 errout << e->toStringAll() << endl;
160 e->destroy();
161 }
163
164 output << sep << endl
165 << L"Finish [" << DateTime::getCurrentLocalTime().toString()
166 << L"]" << endl;
167 }
168#ifdef __DCL_DEBUG
169#if __DCL_HAVE_ALLOC_DEBUG
170 DCLDebugDumpGlobalMemoryLeak(DCL_ALLOC_DUMP_ALL, &errout);
171#endif
172 DCLDebugSetGlobalReport(NULL);
173#endif // __DCL_DEBUG
174 }
175 catch(Exception* e) {
176 String s = e->toStringAll();
177 e->destroy();
178 fwprintf(stderr, L"Warning!! Final Exception: %ls\n", s.data());
179 }
181
182 return 0;
183}
184
185#ifdef __WINNT_NEW_DELETE_OVERRIDE
186#undef new
187__WINNT_NEW_DELETE_OVERRIDE
188#endif
#define __THIS_FILE__
Definition _trace.h:14
#define NULL
Definition Config.h:312
wchar_t char_t
Definition Config.h:247
#define __DCL_THROWS1(e)
Definition Config.h:152
#define STDOUT_HANDLE
Definition File.h:59
#define STDERR_HANDLE
Definition File.h:60
#define __DCL_CLEANUP
Definition Object.h:286
#define __DCL_ASSERT(expr)
Definition Object.h:394
#define __T(str)
Definition Object.h:60
#define __DCL_INITIALIZE
Definition Object.h:285
DCLCVAR const struct __endl endl
virtual String onValidate()
Definition Arguments.cpp:48
String toString() const
Definition DateTime.cpp:843
static DateTime getCurrentLocalTime()
Definition DateTime.cpp:954
virtual void destroy()
Definition Exception.cpp:74
String toStringAll() const
Definition Exception.cpp:45
static String dirname(const String &_path)
Definition Files.cpp:268
static String basename(const String &_path)
Definition Files.cpp:252
static bool isDirectory(const String &_path)
Definition Files.cpp:115
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:67
static void initialize() __DCL_THROWS1(DllException *)
Definition MediaInfo.cpp:51
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)
#define DCL_MEDIA_TAG_VERSION_STRING
__DCL_END_NAMESPACE __DCL_USING_NAMESPACE int main(int argc, char *argv[])
void __main(const MainArguments &_args)