bool CheckAndLoadEmbeddedDocument(xstring fn, std::auto_ptr<document::Document> &doc) { FileEndData::FileEndData fed( fn, true ); if(fed.HasData()) { if(!doc->Load(fn)) { util::error_box(strErrorLoad); exit(-1); } // keep asking user for passphrase until he cancels or inputs correct passphrase. for(;;) { if(!doc->IsKeyValid()) { Plaintext passphrase; if(!DlgPass1::invoke(passphrase)) exit(0); doc->SetKey(passphrase); if(!doc->IsKeyValid()) { util::error_box(strInvalidPassphrase); continue; } } return true; } } else return false; }
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { WindowsInitialization(); gen_tabs(); // initialize AES tables CheckSpecialArgs(); // handle commandline std::auto_ptr<document::Document> doc(new document::Document); if(g_documentFilePath.empty()) { // haven't got a filename, check for embedded data. If we've got embedded data, // make a temp copy of our exe, and launch that with "-edit". If no embedded data, // we'll end up with a blank note instead. FileEndData::FileEndData fed( xstring(g_moduleName), true ); if(fed.HasData()) return CopyAndSpawn() ? 0 : -1; } else { // We've got a filename from commandline, work with that file. if(!CheckAndLoadEmbeddedDocument(g_documentFilePath, doc)) { util::error_box(strErrorLoad); return -1; } } // Now doc is either loaded from our own executable, or blank - start the editor. editor::Editor edit(doc); if(!g_documentFilePath.empty()) edit.UpdateTitle(g_documentFilePath.c_str()); MessageLoop(edit.GetHWND()); if(g_editorMode) { // We were originally launched with "-edit" argument, which means we're running // from a temp file that should be erased. Launch original process to delete temp. //TODO: what if a nosy user is messing with commandline args? xstring args(_T("-erase:\"")); args.append(g_moduleName); args.append(_T("\"")); util::launch(g_documentFilePath, args, false); } return 0; }
bool CopyAndSpawn() { FileEndData::FileEndData fed( xstring(g_moduleName), true ); xstring spawnedEditor; //TODO: make sure temp file doesn't already exist! spawnedEditor = util::get_temp_name(g_editorTempPath, _T("fSekrit"), _T("exe")); if(!util::file_copy_range(spawnedEditor.c_str(), g_moduleName, 0, fed.GetExeSize()) ) { util::error_box(strErrorCopy); return false; } xstring parms(_T("-edit:\"")); parms.append(g_moduleName); parms.append(_T("\"")); util::launch(spawnedEditor, parms, false); return true; }
void websearch_configuration::set_default_engines() { std::string url = "http://www.google.com/search?q=%query&start=%start&num=%num&hl=%lang&ie=%encoding&oe=%encoding"; feed_parser fed("google",url); _se_enabled.add_feed(fed); _se_default.add_feed(fed); feed_url_options fuo(url,"google",true); _se_options.insert(std::pair<const char*,feed_url_options>(fuo._url.c_str(),fuo)); url = "http://www.bing.com/search?q=%query&first=%start&mkt=%lang"; fed = feed_parser("bing",url); _se_enabled.add_feed(fed); _se_default.add_feed(fed); fuo = feed_url_options(url,"bing",true); _se_options.insert(std::pair<const char*,feed_url_options>(fuo._url.c_str(),fuo)); url = "http://search.yahoo.com/search?n=10&ei=UTF-8&va_vt=any&vo_vt=any&ve_vt=any&vp_vt=any&vd=all&vst=0&vf=all&vm=p&fl=1&vl=lang_%lang&p=%query&vs="; fed = feed_parser("yahoo",url); _se_enabled.add_feed(fed); _se_default.add_feed(fed); fuo = feed_url_options(url,"yahoo",true); _se_options.insert(std::pair<const char*,feed_url_options>(fuo._url.c_str(),fuo)); _default_engines = true; }
int main( int argc, char *argv[] ) { cufsetup( argc, argv ); setup_screen( ); fed( ); return 0; }