GEN::Pointer<File> Dump::GetFile(const std::string& filename) { indexIt_t indexIt(_index.find(filename)); const bool miss = _index.end() == indexIt; if(_debug || miss) { FILE* file = fopen(filename.c_str(), "rb"); if(!file) { const unsigned DIR_BUFFER_SIZE = 2048; char dir[DIR_BUFFER_SIZE]; GetCurrentDirectoryA(DIR_BUFFER_SIZE, dir); COM::log << "unable to open file " << filename << " in directory " << dir << std::endl; throw COM::FileNotFoundException(); } fseek(file, 0, SEEK_END); int size = ftell(file); rewind(file); char* memory = new char[size]; fread(memory, size, 1, file); fclose(file); if(miss) { _index[filename] = _indexOff; Crypto(memory, size); // encrypt fseek(_file, _indexOff, SEEK_SET); fwrite(&size, sizeof(int), 1, _file); fwrite(memory, size, 1, _file); _indexOff = ftell(_file); Crypto(memory, size); // decrypt, since memory is passed to file } return GEN::Pointer<File>(new MemFile(filename, memory, size)); } else { fseek(_file, indexIt->second, SEEK_SET); int size; fread(&size, sizeof(int), 1, _file); char* memory = new char[size]; fread(memory, size, 1, _file); Crypto(memory, size); return GEN::Pointer<File>(new MemFile(filename, memory, size)); } return GEN::Pointer<File>(); }
int main(int argc, char *argv[]) { fc::thread::current().set_name( "main" ); QApplication app(argc, argv); app.setApplicationName("Graphene Client"); app.setOrganizationDomain("cryptonomex.org"); app.setOrganizationName("Cryptonomex, Inc."); qRegisterMetaType<std::function<void()>>(); qRegisterMetaType<ObjectId>(); qmlRegisterType<Asset>("Graphene.Client", 0, 1, "Asset"); qmlRegisterType<Balance>("Graphene.Client", 0, 1, "Balance"); qmlRegisterType<Account>("Graphene.Client", 0, 1, "Account"); qmlRegisterType<ChainDataModel>("Graphene.Client", 0, 1, "DataModel"); qmlRegisterType<GrapheneApplication>("Graphene.Client", 0, 1, "GrapheneApplication"); QQmlApplicationEngine engine; QVariant crypto; crypto.setValue(Crypto()); engine.rootContext()->setContextProperty("Crypto", crypto); #ifdef NDEBUG engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); #else QQmlDebuggingEnabler enabler; engine.load(QUrl(QStringLiteral("qml/main.qml"))); #endif return app.exec(); }
void App::Init_Storage() { Digest hash = std::bind( static_cast<bool(CryptoHash::*)( const uint32_t, const std::string&, std::string&)>(&CryptoHash::Digest), &(Crypto().Hash()), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); Random random = std::bind(&CryptoUtil::RandomFilename, &(Crypto().Util())); std::shared_ptr<OTDB::StorageFS> storage(OTDB::StorageFS::Instantiate()); std::string root_path = OTFolders::Common().Get(); std::string path; if (0 <= storage->ConstructAndCreatePath( path, OTFolders::Common().Get(), ".temp")) { path.erase(path.end() - 5, path.end()); } StorageConfig config; config.path_ = path; bool notUsed; Config().CheckSet_bool( "storage", "auto_publish_nyms", config.auto_publish_nyms_, config.auto_publish_nyms_, notUsed); Config().CheckSet_bool( "storage", "auto_publish_servers_", config.auto_publish_servers_, config.auto_publish_servers_, notUsed); Config().CheckSet_bool( "storage", "auto_publish_units_", config.auto_publish_units_, config.auto_publish_units_, notUsed); Config().CheckSet_long( "storage", "gc_interval", config.gc_interval_, config.gc_interval_, notUsed); Config().CheckSet_str( "storage", "path", config.path_, config.path_, notUsed); #ifdef OT_STORAGE_FS Config().CheckSet_str( "storage", "fs_primary", config.fs_primary_bucket_, config.fs_primary_bucket_, notUsed); Config().CheckSet_str( "storage", "fs_secondary", config.fs_secondary_bucket_, config.fs_secondary_bucket_, notUsed); Config().CheckSet_str( "storage", "fs_root_file", config.fs_root_file_, config.fs_root_file_, notUsed); #endif #ifdef OT_STORAGE_SQLITE Config().CheckSet_str( "storage", "sqlite3_primary", config.sqlite3_primary_bucket_, config.sqlite3_primary_bucket_, notUsed); Config().CheckSet_str( "storage", "sqlite3_secondary", config.sqlite3_secondary_bucket_, config.sqlite3_secondary_bucket_, notUsed); Config().CheckSet_str( "storage", "sqlite3_control", config.sqlite3_control_table_, config.sqlite3_control_table_, notUsed); Config().CheckSet_str( "storage", "sqlite3_root_key", config.sqlite3_root_key_, config.sqlite3_root_key_, notUsed); Config().CheckSet_str( "storage", "sqlite3_db_file", config.sqlite3_db_file_, config.sqlite3_db_file_, notUsed); #endif if (nullptr != dht_) { config.dht_callback_ = std::bind( static_cast<void(Dht::*) (const std::string&,const std::string&)>(&Dht::Insert), dht_, std::placeholders::_1, std::placeholders::_2); } storage_ = &Storage::It( hash, random, config); }