int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { wchar_t buf0[MAX_PATH]; GetModuleFileNameW(NULL, buf0, MAX_PATH-1); lString16 str016(buf0); #ifdef _UNICODE lString16 str116(lpCmdLine); #else lString8 str18(lpCmdLine); lString16 str116 = LocalToUnicode(str18); #endif lString8 str0 = UnicodeToUtf8(str016); lString8 str1 = UnicodeToUtf8(str116); if ( !str1.empty() && str1[0]=='\"' ) { // quoted filename support str1.erase(0, 1); int pos = str1.pos(lString8("\"")); if ( pos>=0 ) str1 = str1.substr(0, pos); } char * argv[2]; argv[0] = str0.modify(); argv[1] = str1.modify(); int argc = str1.empty() ? 1 : 2; return main(argc, argv); }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { CRLog::setFileLogger( "crengine.log", true ); CRLog::setLogLevel( CRLog::LL_TRACE ); //InitCREngineLog("/root/abook/crengine/crlog.ini"); #if 0 MMapTest(); #endif lString8 exe_dir; char exe_fn[MAX_PATH+1]; GetModuleFileNameA( NULL, exe_fn, MAX_PATH ); lChar16 exe_fn16[MAX_PATH+1]; GetModuleFileNameW( NULL, exe_fn16, MAX_PATH ); lString16 exedir = LVExtractPath(lString16(exe_fn16)); lString8 exedir8 = UnicodeToUtf8( exedir ); CRLog::debug("exedir=%s", exedir8.c_str()); CRMoFileTranslator * translator = new CRMoFileTranslator(); translator->openMoFile(exedir + L"/po/ru.mo"); CRI18NTranslator::setTranslator( translator ); lChar16 sysdir[MAX_PATH+1]; GetWindowsDirectoryW(sysdir, MAX_PATH); lString16 fontdir( sysdir ); fontdir << L"\\Fonts\\"; lString8 fontdir8( UnicodeToUtf8(fontdir) ); lString8 fd = UnicodeToLocal(exedir); lString16Collection fontDirs; //fontDirs.add( fontdir ); fontDirs.add( exedir + L"fonts" ); InitCREngine( exe_fn, fontDirs ); const char * fontnames[] = { #if 1 "arial.ttf", "ariali.ttf", "arialb.ttf", "arialbi.ttf", #endif "arialn.ttf", "arialni.ttf", "arialnb.ttf", "arialnbi.ttf", "cour.ttf", "couri.ttf", "courbd.ttf", "courbi.ttf", "times.ttf", "timesi.ttf", "timesb.ttf", "timesbi.ttf", #if 0 "comic.ttf", "comicbd.ttf", "verdana.ttf", "verdanai.ttf", "verdanab.ttf", "verdanaz.ttf", "bookos.ttf", "bookosi.ttf", "bookosb.ttf", "bookosbi.ttf", #endif #if 0 "calibri.ttf", "calibrii.ttf", "calibrib.ttf", "calibriz.ttf", "cambria.ttf", "cambriai.ttf", "cambriab.ttf", "cambriaz.ttf", "georgia.ttf", "georgiai.ttf", "georgiab.ttf", "georgiaz.ttf", #endif NULL }; for ( int fi = 0; fontnames[fi]; fi++ ) { fontMan->RegisterFont( fontdir8 + fontnames[fi] ); } //LVCHECKPOINT("WinMain start"); if (!fontMan->GetFontCount()) { //error char str[1000]; #if (USE_FREETYPE==1) sprintf(str, "Cannot open font file(s) fonts/*.ttf \nCannot work without font\nPlace some TTF files to font\\ directory" ); #else sprintf(str, "Cannot open font file(s) font#.lbf \nCannot work without font\nUse FontConv utility to generate .lbf fonts from TTF" ); #endif MessageBoxA( NULL, str, "CR Engine :: Fb2Test -- fatal error!", MB_OK); return 1; } lString8 cmdline(lpCmdLine); if ( cmdline.empty() ) return 2; // need filename hInst = hInstance; MyRegisterClass(hInstance); { CRWin32WindowManager winman(500, 700); const char * keymap_locations [] = { exedir8.c_str(), NULL, }; loadKeymaps( winman, keymap_locations ); ldomDocCache::init( exedir + L"cache", 0x100000 * 96 ); /*96Mb*/ winman.loadSkin( LVExtractPath(LocalToUnicode(lString8(exe_fn))) + L"skin" ); V3DocViewWin * main_win = new V3DocViewWin( &winman, LVExtractPath(LocalToUnicode(lString8(exe_fn))) ); main_win->getDocView()->setBackgroundColor(0xFFFFFF); main_win->getDocView()->setTextColor(0x000000); main_win->getDocView()->setFontSize( 20 ); main_win->loadCSS( exedir + L"fb2.css" ); main_win->loadSettings( exedir + L"cr3.ini" ); main_win->saveSettings(lString16()); main_win->setHelpFile( exedir + L"cr3-manual-ru.fb2" ); HyphMan::initDictionaries( exedir + L"hyph\\" ); main_win->loadDefaultCover( exedir + L"cr3_def_cover.png" ); main_win->setBookmarkDir(lString16("c:\\cr3\\bookmarks\\")); lString8 exedir8 = UnicodeToUtf8( exedir ); const char * dirs[] = { exedir8.c_str(), NULL }; loadKeymaps( winman, dirs ); main_win->loadHistory( exedir + L"cr3hist.bmk" ); winman.activateWindow( main_win ); if ( !main_win->loadDocument( LocalToUnicode( cmdline )) ) { char str[100]; sprintf(str, "Cannot open document file %s", cmdline.c_str()); MessageBoxA( NULL, str, "CR Engine :: Fb2Test -- fatal error!", MB_OK); return 1; } else { winman.runEventLoop(); } } //ShutdownFontManager(); return 0; }
int main(int argc, char *argv[]) { int res = 0; { Device::instance(); // initialize device #ifndef i386 QProcess::execute("eips -c"); pTouch = new TouchScreen(); #endif lString16 exedir = LVExtractPath(LocalToUnicode(lString8(argv[0]))); LVAppendPathDelimiter(exedir); lString16 datadir = exedir + "data/"; lString16 exefontpath = exedir + "fonts"; lString16Collection fontDirs; fontDirs.add(exefontpath); #ifndef i386 fontDirs.add("/usr/java/lib/fonts"); fontDirs.add("/mnt/us/fonts"); #endif CRPropRef props = LVCreatePropsContainer(); { LVStreamRef cfg = LVOpenFileStream(UnicodeToUtf8(datadir + "cr3.ini").data(), LVOM_READ); if(!cfg.isNull()) props->loadFromStream(cfg.get()); } lString16 lang = props->getStringDef(PROP_WINDOW_LANG, ""); InitCREngineLog(props); CRLog::info("main()"); if(!InitCREngine(argv[0], fontDirs)) { printf("Cannot init CREngine - exiting\n"); return 2; } #ifndef i386 PrintString(1, 1, "crengine version: " + QString(CR_ENGINE_VERSION)); PrintString(1, 2, QString("build date: %1 %2").arg(__DATE__).arg(__TIME__)); if (!Device::isTouch()) { QString message = "Please wait while application is loading..."; int xpos = ((Device::getWidth()/12-1)-message.length())/2; int ypos = (Device::getHeight()/20-2)/2; PrintString(xpos, ypos, message); } #endif // to catch crashes and remove current cache file on crash (SIGSEGV etc.) crSetSignalHandler(); // set row count depending on device model (used in lists) int rc = props->getIntDef(PROP_WINDOW_ROW_COUNT, 0); if(!rc) { #ifndef i386 switch(Device::getModel()) { case Device::KDX: rc = 20; break; case Device::KT: case Device::KPW: rc = 8; break; default: rc = 10; } props->setInt(PROP_WINDOW_ROW_COUNT, rc); #else props->setInt(PROP_WINDOW_ROW_COUNT, 10); #endif LVStreamRef cfg = LVOpenFileStream(UnicodeToUtf8(datadir + "cr3.ini").data(), LVOM_WRITE); props->saveToStream(cfg.get()); } QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); MyApplication a(argc, argv); pMyApp = &a; // set app stylesheet #ifndef i386 QString style = Device::isTouch() ? "stylesheet_pw.qss" : "stylesheet_k3.qss"; QFile qss(QDir::toNativeSeparators(cr2qt(datadir)) + style); // set up full update interval for the graphics driver Device::setFullScreenUpdateEvery(props->getIntDef(PROP_DISPLAY_FULL_UPDATE_INTERVAL, 1)); #else QFile qss(QDir::toNativeSeparators(cr2qt(datadir)) + "stylesheet_k3.qss"); #endif qss.open(QFile::ReadOnly); if(qss.error() == QFile::NoError) { a.setStyleSheet(qss.readAll()); qss.close(); } QMap<QString, QString> langToCode; langToCode["Russian"] = "ru"; langToCode["French"] = "fr"; langToCode["Hungarian"] = "hu"; langToCode["Italian"] = "it"; langToCode["German"] = "de"; langToCode["Ukrainian"] = "uk"; QString translations = cr2qt(datadir) + "i18n"; QTranslator myappTranslator, qtr; if (!lang.empty() && lang.compare("English")) { QString lng = cr2qt(lang); if (myappTranslator.load(lng, translations)) { // default translator for Qt standard dialogs if (qtr.load("qt_" + langToCode[lng], translations)) { QApplication::installTranslator(&qtr); } else { qDebug() << "Failed to load Qt translation for " << lng; } // load after default to allow overriding translations QApplication::installTranslator(&myappTranslator); } else { qDebug() << "Can`t load translation file " << lng << " from dir " << translations; } } (void) signal(SIGUSR1, sigCatcher); MainWindow mainWin; a.setMainWindow(&mainWin); mainWin.showFullScreen(); mainWin.doStartupActions(); res = a.exec(); } ShutdownCREngine(); return res; }
int main(int argc, char *argv[]) { int res = 0; { #ifdef DEBUG lString8 loglevel("TRACE"); lString8 logfile("stdout"); #else lString8 loglevel("ERROR"); lString8 logfile("stderr"); #endif for ( int i=1; i<argc; i++ ) { if ( !strcmp("-h", argv[i]) || !strcmp("-?", argv[i]) || !strcmp("/?", argv[i]) || !strcmp("--help", argv[i]) ) { printHelp(); return 0; } if ( !strcmp("-v", argv[i]) || !strcmp("/v", argv[i]) || !strcmp("--version", argv[i]) ) { printVersion(); return 0; } if ( !strcmp("--stats", argv[i]) && i<argc-4 ) { if ( i!=argc-5 ) { printf("To calculate character encoding statistics, use cr3 <infile.txt> <outfile.cpp> <codepagename> <langname>\n"); return 1; } lString8 list; FILE * out = fopen(argv[i+2], "wb"); if ( !out ) { printf("Cannot create file %s", argv[i+2]); return 1; } MakeStatsForFile( argv[i+1], argv[i+3], argv[i+4], 0, out, list ); fclose(out); return 0; } lString8 s(argv[i]); if ( s.startsWith(lString8("--loglevel=")) ) { loglevel = s.substr(11, s.length()-11); } else if ( s.startsWith(lString8("--logfile=")) ) { logfile = s.substr(10, s.length()-10); } } // set logger if ( logfile=="stdout" ) CRLog::setStdoutLogger(); else if ( logfile=="stderr" ) CRLog::setStderrLogger(); else if ( !logfile.empty() ) CRLog::setFileLogger(logfile.c_str()); if ( loglevel=="TRACE" ) CRLog::setLogLevel(CRLog::LL_TRACE); else if ( loglevel=="DEBUG" ) CRLog::setLogLevel(CRLog::LL_DEBUG); else if ( loglevel=="INFO" ) CRLog::setLogLevel(CRLog::LL_INFO); else if ( loglevel=="WARN" ) CRLog::setLogLevel(CRLog::LL_WARN); else if ( loglevel=="ERROR" ) CRLog::setLogLevel(CRLog::LL_ERROR); else CRLog::setLogLevel(CRLog::LL_FATAL); lString16 exename = LocalToUnicode( lString8(argv[0]) ); lString16 exedir = LVExtractPath(exename); lString16 datadir = lString16(CR3_DATA_DIR); LVAppendPathDelimiter(exedir); LVAppendPathDelimiter(datadir); lString16 exefontpath = exedir + L"fonts"; CRLog::info("main()"); lString16Collection fontDirs; //fontDirs.add( lString16(L"/usr/local/share/crengine/fonts") ); //fontDirs.add( lString16(L"/usr/local/share/fonts/truetype/freefont") ); //fontDirs.add( lString16(L"/mnt/fonts") ); #if 0 fontDirs.add( exefontpath ); fontDirs.add( lString16(L"/usr/share/fonts/truetype") ); fontDirs.add( lString16(L"/usr/share/fonts/truetype/liberation") ); fontDirs.add( lString16(L"/usr/share/fonts/truetype/freefont") ); #endif // TODO: use fontconfig instead //fontDirs.add( lString16(L"/root/fonts/truetype") ); if ( !InitCREngine( argv[0], fontDirs ) ) { printf("Cannot init CREngine - exiting\n"); return 2; } if ( argc>=2 && !strcmp(argv[1], "unittest") ) { #ifdef _DEBUG runTinyDomUnitTests(); #endif CRLog::info("UnitTests finished: exiting"); return 0; } //if ( argc!=2 ) { // printf("Usage: cr3 <filename_to_open>\n"); // return 3; //} { QApplication a(argc, argv); #ifdef _WIN32 QString exeDir = QDir::toNativeSeparators(qApp->applicationDirPath() + "/"); //QDir::separator(); QString translations = exeDir + "i18n"; #else QString exeDir = cr2qt(datadir); QString translations = exeDir + "i18n/"; #endif QTranslator qtTranslator; if (qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) QApplication::installTranslator(&qtTranslator); QTranslator myappTranslator; QString trname = "cr3_" + QLocale::system().name(); CRLog::info("Using translation file %s from dir %s", UnicodeToUtf8(qt2cr(trname)).c_str(), UnicodeToUtf8(qt2cr(translations)).c_str() ); if ( myappTranslator.load(trname, translations) ) QApplication::installTranslator(&myappTranslator); else CRLog::error("Canot load translation file %s from dir %s", UnicodeToUtf8(qt2cr(trname)).c_str(), UnicodeToUtf8(qt2cr(translations)).c_str() ); MainWindow w; w.show(); res = a.exec(); } } ShutdownCREngine(); return res; }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { CRLog::setFileLogger( "crengine.log" ); CRLog::setLogLevel( CRLog::LL_TRACE ); // TODO: Place code here. MSG msg; HACCEL hAccelTable; //make_dither_table(); //TestWol(); /* LVStreamRef zipfile = LVOpenFileStream( L"zip_test.zip", LVOM_READ ); if (!zipfile.isNull()) { LVContainerRef zip = LVOpenArchieve( zipfile ); if (!zip.isNull()) { LVStreamRef log = LVOpenFileStream("ziptest.log", LVOM_WRITE); for (int i=0; i<zip->GetObjectCount(); i++) { const LVContainerItemInfo * item = zip->GetObjectInfo(i); if (item) { // *log << UnicodeToLocal( item->GetName() ); *log << lString8::itoa( (int)item->GetSize() ); LVStreamRef unpstream = zip->OpenStream( item->GetName(), LVOM_READ ); if (!unpstream.isNull()) { *log << "\n arc stream opened ok \n"; LVStreamRef outstream = LVOpenFileStream( item->GetName(), LVOM_WRITE ); if ( !outstream.isNull() ) { int copiedBytes = (int)LVPumpStream( outstream, unpstream ); *log << " copied " << lString8::itoa(copiedBytes) << " bytes\n"; } else { *log << " error opening out stream\n"; } } } } } } */ lString8 exe_dir; char exe_fn[MAX_PATH+1]; GetModuleFileNameA( NULL, exe_fn, MAX_PATH ); int last_slash = -1; int i; for (i=0; exe_fn[i]; i++) if (exe_fn[i]=='\\' || exe_fn[i]=='/') last_slash = i; if (last_slash>0) exe_dir = lString8( exe_fn, last_slash ); // init hyphenation manager initHyph( (exe_dir + "\\russian_EnUS_hyphen_(Alan).pdb").c_str() ); lString8 fontDir = exe_dir; fontDir << "\\fonts"; // init bitmap font manager InitFontManager( fontDir ); // Load font definitions into font manager // fonts are in files font1.lbf, font2.lbf, ... font32.lbf #if (USE_FREETYPE==1) LVContainerRef dir = LVOpenDirectory( LocalToUnicode(fontDir).c_str() ); if ( !dir.isNull() ) for ( i=0; i<dir->GetObjectCount(); i++ ) { const LVContainerItemInfo * item = dir->GetObjectInfo(i); lString16 fileName = item->GetName(); if ( !item->IsContainer() && fileName.length()>4 && lString16(fileName, fileName.length()-4, 4)==L".ttf" ) { lString8 fn = UnicodeToLocal(fileName); printf("loading font: %s\n", fn.c_str()); if ( !fontMan->RegisterFont(fn) ) { printf(" failed\n"); } } } //fontMan->RegisterFont(lString8("arial.ttf")); #else #if (USE_WIN32_FONTS==0) #define MAX_FONT_FILE 32 for (i=0; i<MAX_FONT_FILE; i++) { char fn[32]; sprintf( fn, "font%d.lbf", i ); fontMan->RegisterFont( lString8(fn) ); } #endif #endif //LVCHECKPOINT("WinMain start"); text_view = new LVDocView; // stylesheet can be placed to file fb2.css // if not found, default stylesheet will be used lString8 css = readFileToString( (exe_dir + "\\fb2.css").c_str() ); if (css.length() > 0) text_view->setStyleSheet( css ); //LVCHECKPOINT("WinMain before loads"); if (!fontMan->GetFontCount()) { //error char str[1000]; #if (USE_FREETYPE==1) sprintf(str, "Cannot open font file(s) fonts/*.ttf \nCannot work without font\nPlace some TTF files to font\\ directory" ); #else sprintf(str, "Cannot open font file(s) font#.lbf \nCannot work without font\nUse FontConv utility to generate .lbf fonts from TTF" ); #endif MessageBoxA( NULL, str, "CR Engine :: Fb2Test -- fatal error!", MB_OK); return 1; } lString8 cmdline(lpCmdLine); cmdline.trim(); if ( cmdline == "test_format" ) { testFormatting(); return 1; } if (cmdline.empty()) { cmdline = OpenFileDialog( NULL ); //cmdline = "example2.fb2"; } if ( cmdline.empty() ) return 2; if ( !text_view->LoadDocument( cmdline.c_str() )) { //error char str[100]; sprintf(str, "Cannot open document file %s", cmdline.c_str()); MessageBoxA( NULL, str, "CR Engine :: Fb2Test -- fatal error!", MB_OK); return 1; } //LVCHECKPOINT("WinMain after loads"); // Initialize global strings MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_FONTTEST); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } delete text_view; ShutdownFontManager(); return msg.wParam; }
int main(int argc, char *argv[]) { int res = 0; { Device::instance(); // initialize device #ifndef i386 QProcess::execute("eips -c"); pTouch = new TouchScreen(); #endif lString16 exedir = LVExtractPath(LocalToUnicode(lString8(argv[0]))); LVAppendPathDelimiter(exedir); lString16 datadir = exedir + L"data/"; lString16 exefontpath = exedir + L"fonts"; lString16Collection fontDirs; fontDirs.add(exefontpath); #ifndef i386 fontDirs.add(lString16(L"/usr/java/lib/fonts")); fontDirs.add(lString16(L"/mnt/us/fonts")); #endif CRPropRef props = LVCreatePropsContainer(); { LVStreamRef cfg = LVOpenFileStream(UnicodeToUtf8(datadir + L"cr3.ini").data(), LVOM_READ); if(!cfg.isNull()) props->loadFromStream(cfg.get()); } lString16 lang = props->getStringDef(PROP_WINDOW_LANG, ""); InitCREngineLog(props); CRLog::info("main()"); if(!InitCREngine(argv[0], fontDirs)) { printf("Cannot init CREngine - exiting\n"); return 2; } #ifndef i386 PrintString(1, 1, "crengine version: " + QString(CR_ENGINE_VERSION)); PrintString(1, 2, QString("buid date: %1 %2").arg(__DATE__).arg(__TIME__)); if (!Device::isTouch()) { QString message = "Please wait while application is loading..."; int xpos = ((Device::getWidth()/12-1)-message.length())/2; int ypos = (Device::getHeight()/20-2)/2; PrintString(xpos, ypos, message); } #endif // set row count int rc = props->getIntDef(PROP_WINDOW_ROW_COUNT, 0); if(!rc) { #ifndef i386 props->setInt(PROP_WINDOW_ROW_COUNT, Device::getModel() != Device::KDX ? 10 : 16); #else props->setInt(PROP_WINDOW_ROW_COUNT, 10); #endif LVStreamRef cfg = LVOpenFileStream(UnicodeToUtf8(datadir + L"cr3.ini").data(), LVOM_WRITE); props->saveToStream(cfg.get()); } QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); MyApplication a(argc, argv); pMyApp = &a; // set app stylesheet #ifndef i386 QString style = (Device::getModel() != Device::KDX ? "stylesheet_k3.qss" : "stylesheet_dx.qss"); if (Device::getModel() == Device::KPW) style = "stylesheet_pw.qss"; QFile qss(QDir::toNativeSeparators(cr2qt(datadir)) + style); // set up full update interval for the graphics driver QKindleFb *pscreen = static_cast<QKindleFb*>(QScreen::instance()); pscreen->setFullUpdateEvery(props->getIntDef(PROP_DISPLAY_FULL_UPDATE_INTERVAL, 1)); #else QFile qss(QDir::toNativeSeparators(cr2qt(datadir)) + "stylesheet_k3.qss"); #endif qss.open(QFile::ReadOnly); if(qss.error() == QFile::NoError) { a.setStyleSheet(qss.readAll()); qss.close(); } QString translations = cr2qt(datadir) + "i18n"; QTranslator myappTranslator; if(!lang.empty() && lang.compare(L"English")) { if(myappTranslator.load(cr2qt(lang), translations)) QApplication::installTranslator(&myappTranslator); else qDebug("Can`t load translation file %s from dir %s", UnicodeToUtf8(lang).c_str(), UnicodeToUtf8(qt2cr(translations)).c_str()); } (void) signal(SIGUSR1, sigCatcher); MainWindow mainWin; a.setMainWindow(&mainWin); mainWin.showFullScreen(); mainWin.doStartupActions(); res = a.exec(); } ShutdownCREngine(); return res; }