mirror of https://github.com/aria2/aria2
Suppress console output for none-standalone mode
parent
315c05ea3c
commit
d07b3ff8d9
|
@ -43,8 +43,8 @@ class NullOutputFile:public OutputFile {
|
|||
public:
|
||||
virtual ~NullOutputFile() {}
|
||||
virtual size_t write(const char* str) { return 0; }
|
||||
virtual int vprintf(const char* format, va_list va) { return 0; }
|
||||
virtual int flush() { return 0; }
|
||||
virtual int vprintf(const char* format, va_list va) { return 0; }
|
||||
virtual bool supportsColor() { return false; }
|
||||
};
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
#include "BitfieldMan.h"
|
||||
#include "DownloadContext.h"
|
||||
#include "RpcMethodImpl.h"
|
||||
#include "console.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -72,6 +73,7 @@ Platform* platform = 0;
|
|||
|
||||
int libraryInit()
|
||||
{
|
||||
global::initConsole(true);
|
||||
try {
|
||||
platform = new Platform();
|
||||
} catch(RecoverableException& e) {
|
||||
|
|
|
@ -33,38 +33,47 @@
|
|||
*/
|
||||
/* copyright --> */
|
||||
#include "console.h"
|
||||
#include "NullOutputFile.h"
|
||||
#ifdef __MINGW32__
|
||||
# include "WinConsoleFile.h"
|
||||
#else // !__MINGW32__
|
||||
# include "BufferedFile.h"
|
||||
#endif // !__MINGW32__
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
namespace global {
|
||||
|
||||
#ifdef __MINGW32__
|
||||
const SharedHandle<WinConsoleFile>& cout()
|
||||
{
|
||||
static SharedHandle<WinConsoleFile> f(new WinConsoleFile(STD_OUTPUT_HANDLE));
|
||||
return f;
|
||||
}
|
||||
#else // !__MINGW32__
|
||||
const SharedHandle<BufferedFile>& cout()
|
||||
{
|
||||
static SharedHandle<BufferedFile> f(new BufferedFile(stdout));
|
||||
return f;
|
||||
}
|
||||
#endif // !__MINGW32__
|
||||
namespace {
|
||||
Console consoleCout;
|
||||
Console consoleCerr;
|
||||
};
|
||||
|
||||
void initConsole(bool suppress)
|
||||
{
|
||||
if(suppress) {
|
||||
consoleCerr.reset(new NullOutputFile());
|
||||
consoleCout.reset(new NullOutputFile());
|
||||
} else {
|
||||
#ifdef __MINGW32__
|
||||
const SharedHandle<WinConsoleFile>& cerr()
|
||||
{
|
||||
static SharedHandle<WinConsoleFile> f(new WinConsoleFile(STD_ERROR_HANDLE));
|
||||
return f;
|
||||
}
|
||||
consoleCout.reset(new WinConsoleFile(STD_OUTPUT_HANDLE));
|
||||
consoleCerr.reset(new WinConsoleFile(STD_ERROR_HANDLE));
|
||||
#else // !__MINGW32__
|
||||
const SharedHandle<BufferedFile>& cerr()
|
||||
{
|
||||
static SharedHandle<BufferedFile> f(new BufferedFile(stderr));
|
||||
return f;
|
||||
}
|
||||
consoleCout.reset(new BufferedFile(stdout));
|
||||
consoleCerr.reset(new BufferedFile(stderr));
|
||||
#endif // !__MINGW32__
|
||||
}
|
||||
}
|
||||
|
||||
const Console& cout()
|
||||
{
|
||||
return consoleCout;
|
||||
}
|
||||
|
||||
const Console& cerr()
|
||||
{
|
||||
return consoleCerr;
|
||||
}
|
||||
|
||||
} // namespace global
|
||||
|
||||
|
|
|
@ -37,22 +37,18 @@
|
|||
|
||||
#include "common.h"
|
||||
#include "SharedHandle.h"
|
||||
#ifdef __MINGW32__
|
||||
# include "WinConsoleFile.h"
|
||||
#else // !__MINGW32__
|
||||
# include "BufferedFile.h"
|
||||
#endif // !__MINGW32__
|
||||
#include "OutputFile.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
#ifdef __MINGW32__
|
||||
typedef SharedHandle<WinConsoleFile> Console;
|
||||
#else // !__MINGW32__
|
||||
typedef SharedHandle<BufferedFile> Console;
|
||||
#endif // !__MINGW32__
|
||||
typedef SharedHandle<OutputFile> Console;
|
||||
|
||||
namespace global {
|
||||
|
||||
// Initialize console output facility. If the |suppress| is true, all
|
||||
// output sent to the console objects are discarded.
|
||||
void initConsole(bool suppress);
|
||||
|
||||
const Console& cout();
|
||||
const Console& cerr();
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ error_code::Value main(int argc, char** argv)
|
|||
int main(int argc, char** argv)
|
||||
{
|
||||
aria2::error_code::Value r;
|
||||
aria2::global::initConsole(false);
|
||||
try {
|
||||
aria2::Platform platform;
|
||||
r = aria2::main(argc, argv);
|
||||
|
|
|
@ -9,8 +9,10 @@
|
|||
#include "Platform.h"
|
||||
#include "SocketCore.h"
|
||||
#include "util.h"
|
||||
#include "console.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
aria2::global::initConsole(false);
|
||||
aria2::Platform platform;
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
|
|
Loading…
Reference in New Issue