void Plugin::SetGuid(const GUID& Guid) { m_Guid = Guid; m_strGuid = GuidToStr(m_Guid); }
bool Plugin::SaveToCache() { PluginInfo Info = {sizeof(Info)}; GetPluginInfo(&Info); auto& PlCache = *ConfigProvider().PlCacheCfg(); SCOPED_ACTION(auto)(PlCache.ScopedTransaction()); PlCache.DeleteCache(m_strCacheName); unsigned __int64 id = PlCache.CreateCache(m_strCacheName); { bool bPreload = (Info.Flags & PF_PRELOAD); PlCache.SetPreload(id, bPreload); WorkFlags.Change(PIWF_PRELOADED, bPreload); if (bPreload) { PlCache.EndTransaction(); return true; } } { string strCurPluginID; os::FAR_FIND_DATA fdata; os::GetFindDataEx(m_strModuleName, fdata); strCurPluginID = str_printf( L"%I64x%x%x", fdata.nFileSize, fdata.ftCreationTime.dwLowDateTime, fdata.ftLastWriteTime.dwLowDateTime ); PlCache.SetSignature(id, strCurPluginID); } for (size_t i = 0; i < Info.DiskMenu.Count; i++) { PlCache.SetDiskMenuItem(id, i, Info.DiskMenu.Strings[i], GuidToStr(Info.DiskMenu.Guids[i])); } for (size_t i = 0; i < Info.PluginMenu.Count; i++) { PlCache.SetPluginsMenuItem(id, i, Info.PluginMenu.Strings[i], GuidToStr(Info.PluginMenu.Guids[i])); } for (size_t i = 0; i < Info.PluginConfig.Count; i++) { PlCache.SetPluginsConfigMenuItem(id, i, Info.PluginConfig.Strings[i], GuidToStr(Info.PluginConfig.Guids[i])); } PlCache.SetCommandPrefix(id, NullToEmpty(Info.CommandPrefix)); PlCache.SetFlags(id, Info.Flags); PlCache.SetMinFarVersion(id, &MinFarVersion); PlCache.SetGuid(id, m_strGuid); PlCache.SetVersion(id, &PluginVersion); PlCache.SetTitle(id, strTitle); PlCache.SetDescription(id, strDescription); PlCache.SetAuthor(id, strAuthor); m_model->SaveExportsToCache(PlCache, id, Exports); return true; }
int CgptBoot(CgptBootParams *params) { struct drive drive; int retval = 1; int gpt_retval= 0; int mode = O_RDONLY; if (params == NULL) return CGPT_FAILED; if (params->create_pmbr || params->partition || params->bootfile) mode = O_RDWR; if (CGPT_OK != DriveOpen(params->drive_name, &drive, mode, params->drive_size)) { return CGPT_FAILED; } if (CGPT_OK != ReadPMBR(&drive)) { Error("Unable to read PMBR\n"); goto done; } if (params->create_pmbr) { drive.pmbr.magic[0] = 0x1d; drive.pmbr.magic[1] = 0x9a; drive.pmbr.sig[0] = 0x55; drive.pmbr.sig[1] = 0xaa; memset(&drive.pmbr.part, 0, sizeof(drive.pmbr.part)); drive.pmbr.part[0].f_head = 0x00; drive.pmbr.part[0].f_sect = 0x02; drive.pmbr.part[0].f_cyl = 0x00; drive.pmbr.part[0].type = 0xee; drive.pmbr.part[0].l_head = 0xff; drive.pmbr.part[0].l_sect = 0xff; drive.pmbr.part[0].l_cyl = 0xff; drive.pmbr.part[0].f_lba = htole32(1); uint32_t max = 0xffffffff; if (drive.gpt.streaming_drive_sectors < 0xffffffff) max = drive.gpt.streaming_drive_sectors - 1; drive.pmbr.part[0].num_sect = htole32(max); } if (params->partition) { if (GPT_SUCCESS != (gpt_retval = GptSanityCheck(&drive.gpt))) { Error("GptSanityCheck() returned %d: %s\n", gpt_retval, GptError(gpt_retval)); goto done; } if (params->partition > GetNumberOfEntries(&drive)) { Error("invalid partition number: %d\n", params->partition); goto done; } uint32_t index = params->partition - 1; GptEntry *entry = GetEntry(&drive.gpt, ANY_VALID, index); memcpy(&drive.pmbr.boot_guid, &entry->unique, sizeof(Guid)); } if (params->bootfile) { int fd = open(params->bootfile, O_RDONLY); if (fd < 0) { Error("Can't read %s: %s\n", params->bootfile, strerror(errno)); goto done; } int n = read(fd, drive.pmbr.bootcode, sizeof(drive.pmbr.bootcode)); if (n < 1) { Error("problem reading %s: %s\n", params->bootfile, strerror(errno)); close(fd); goto done; } close(fd); } char buf[GUID_STRLEN]; GuidToStr(&drive.pmbr.boot_guid, buf, sizeof(buf)); printf("%s\n", buf); // Write it all out, if needed. if (mode == O_RDONLY || CGPT_OK == WritePMBR(&drive)) retval = 0; done: (void) DriveClose(&drive, 1); return retval; }
bool SQLiteDb::Open(string_view const DbFile, bool Local, bool WAL) { const auto& v1_opener = [](string_view const Name, database_ptr& Db) { return sqlite::sqlite3_open16(null_terminated(Name).c_str(), &ptr_setter(Db)) == SQLITE_OK; }; const auto& v2_opener = [WAL](string_view const Name, database_ptr& Db) { return sqlite::sqlite3_open_v2(encoding::utf8::get_bytes(Name).c_str(), &ptr_setter(Db), WAL? SQLITE_OPEN_READWRITE : SQLITE_OPEN_READONLY, nullptr) == SQLITE_OK; }; m_Path = GetDatabasePath(DbFile, Local); const auto mem_db = DbFile == MemoryDbName; if (!Global->Opt->ReadOnlyConfig || mem_db) { if (!mem_db && db_exists < 0) { db_exists = os::fs::is_file(m_Path)? +1 : 0; } if (!v1_opener(m_Path, m_Db)) return false; sqlite::sqlite3_busy_timeout(m_Db.get(), 1000); return true; } // copy db to memory // if (!v1_opener(MemoryDbName, m_Db)) return false; bool ok = true, copied = false; if (os::fs::is_file(m_Path)) { database_ptr db_source; if (db_exists < 0) db_exists = +1; if (WAL && !can_create_file(concat(m_Path, L'.', GuidToStr(CreateUuid())))) // can't open db -- copy to %TEMP% { string strTmp; os::fs::GetTempPath(strTmp); append(strTmp, str(GetCurrentProcessId()), L'-', DbFile); ok = copied = os::fs::copy_file(m_Path, strTmp, nullptr, nullptr, nullptr, 0); if (ok) { os::fs::set_file_attributes(strTmp, FILE_ATTRIBUTE_NORMAL); m_Path = strTmp; ok = v1_opener(m_Path, db_source); } } else { ok = v2_opener(m_Path, db_source); } if (ok) { sqlite::sqlite3_busy_timeout(db_source.get(), 1000); const auto db_backup = sqlite::sqlite3_backup_init(m_Db.get(), "main", db_source.get(), "main"); ok = (nullptr != db_backup); if (ok) { sqlite::sqlite3_backup_step(db_backup, -1); sqlite::sqlite3_backup_finish(db_backup); ok = sqlite::sqlite3_errcode(m_Db.get()) == SQLITE_OK; } } } if (copied) os::fs::delete_file(m_Path); assign(m_Path, MemoryDbName); if (!ok) Close(); return ok; }
string detail::CreateEventName() { return GuidToStr(CreateUuid()); }