int trap_RenameFile(lua_State *s) { const char *oldname, *newname; trap_args(s, "RenameFile", "ss", &oldname, &newname); oldname = datapath(oldname); newname = datapath(newname); if (rename(oldname, newname) < 0) { FATAL("Failed to rename file from \"%s\" to \"%s\"", oldname, newname); } return 0; }
void friend_history_clear(FRIEND *f) { uint8_t path[512], *p; message_clear(&messages_friend, &f->msg); { /* We get the file path of the log file */ p = path + datapath(path); if(countof(path) - (p - path) < TOX_PUBLIC_KEY_SIZE * 2 + sizeof(LOGFILE_EXT)) { /* We ensure that we have enough space in the buffer, if not we fail */ debug("error/history_clear: path too long\n"); return; } cid_to_string(p, f->cid); p += TOX_PUBLIC_KEY_SIZE * 2; memcpy((char*)p, LOGFILE_EXT, sizeof(LOGFILE_EXT)); } remove((const char *)path); }
int trap_ReadDirectory(lua_State *s) { directory_t *dir; direntry_t *ent; const char *path; int i; trap_args(s, "ReadDirectory", "s", &path); path = datapath(path); dir = OPENDIR(path); if (dir == NULL) FATAL("Failed to open directory: %s", path); lua_newtable(s); i = 1; for (ent = READDIR(dir); ent != NULL; ent = READDIR(dir)) { path = DIRENT_NAME(ent); if (strcmp(path, ".") == 0) continue; if (strcmp(path, "..") == 0) continue; lua_pushstring(s, va("%d", i)); lua_pushstring(s, DIRENT_NAME(ent)); lua_settable(s, -3); ++i; } CLOSEDIR(dir); return 1; }
void ProfileManager::store_profile(std::string profilename, profile_ptr p) { // If profile_ptr empty, nothing to store if (!p.get()) { cout << "[BroadMask] Not storing empty profile_ptr for " << profilename << endl; return; } std::map<std::string, std::string>::iterator it = profiles.find(profilename); if (it == profiles.end()) return; fs::path profilepath = broadmask_root(); profilepath /= profilename; fs::path datapath (profilepath / kProfileStorageFile); std::stringstream os; Profile::store(p, os); std::string keyid = it->second; // Encode Profile as Base64, as Instances are // manually serialized, and may contain \0 characters std::string istore_str = base64_encode(os.str()); gpgme_result enc_result = gpgme_encrypt_tofile(istore_str.data(), keyid.c_str(), datapath.string().c_str()); if (enc_result.error) { cerr << "[BroadMask] Could not store profile " << profilename << ". Error was: " << enc_result.error_msg << endl; } }
profile_ptr ProfileManager::unlock_profile(FB::DOM::WindowPtr window, std::string profilename) { profile_ptr p = profile_ptr(); if (profilename.size() == 0) { profilename = last_profile; } // Request permission from user if domain unknown //if (!has_user_ack(profilename, window)) // return p; // if Profile matches active profile if (is_active_and_valid(profilename)) return active_profile; std::map<std::string, std::string>::iterator it = profiles.find(profilename); if (it == profiles.end()) return p; // No such profile fs::path profilepath = broadmask_root(); profilepath /= profilename; fs::path datapath (profilepath / kProfileStorageFile); // Profile has not been created or Profile Storage not existant // then create it and return new storage if (!fs::is_directory(profilepath) || !fs::is_regular_file(datapath)) { fs::create_directories(profilepath); boost::shared_ptr<Profile> p(new Profile(profilename, it->second)); return make_active(p); } // Test if file is empty, in which case delete it and return new storage if (fs::is_empty(datapath)) { cout << "Found empty profile.data for profile " << profilename << endl; fs::remove(datapath); boost::shared_ptr<Profile> p(new Profile(profilename, it->second)); return make_active(p); } // Read file gpgme_result dec_result = gpgme_decrypt_file(datapath.string().c_str()); if (dec_result.error) { cerr << "[BroadMask] Could not load profile " << profilename << ". Error was: " << dec_result.error_msg << endl; p.reset(); return p; } // Use recovered plaintext to load Profile std::string recovered = base64_decode(std::string(dec_result.result)); std::istringstream is(recovered); p = Profile::load(is); return make_active(p); }
int trap_LoadFile(lua_State *s) { const char *path; FILE *f; size_t n; static char data[MAX_FILE]; trap_args(s, "LoadFile", "s", &path); f = fopen(datapath(path), "rb"); if (f == NULL) FATAL("Could not open file: %s", datapath(path)); n = fread(data, 1, MAX_FILE, f); fclose(f); data[n] = 0; lua_pushstring(s, data); return 1; }
int trap_CheckFile(lua_State *s) { const char *path; trap_args(s, "CheckFile", "s", &path); lua_pushboolean(s, sys_exists(datapath(path))); return 1; }
int trap_IsFile(lua_State *s) { const char *path; trap_args(s, "IsFile", "s", &path); lua_pushboolean(s, sys_isfile(datapath(path))); return 1; }
int trap_IsDirectory(lua_State *s) { const char *path; trap_args(s, "IsDirectory", "s", &path); lua_pushboolean(s, sys_isdir(datapath(path))); return 1; }
int trap_RemoveDirectory(lua_State *s) { const char *dir; trap_args(s, "RemoveDirectory", "s", &dir); dir = datapath(dir); if (RMDIR(dir) < 0) { FATAL("Failed to remove directory: %s", dir); } return 0; }
int trap_RemoveFile(lua_State *s) { const char *file; trap_args(s, "RemoveFile", "s", &file); file = datapath(file); if (remove(file) < 0) { FATAL("Failed to remove file: %s", file); } return 0; }
int trap_MakeDirectory(lua_State *s) { const char *dir; trap_args(s, "MakeDirectory", "s", &dir); dir = datapath(dir); if (MKDIR(dir)) { FATAL("Failed to make directory: %s", dir); } return 0; }
int trap_OpenFile(lua_State *s) { const char *file, *mode, *fullpath; FILE *fp; trap_args(s, "OpenFile", "ss", &file, &mode); fullpath = datapath(file); fp = fopen(fullpath, mode); if (fp == NULL) FATAL("Failed to open file: %s", fullpath); lua_pushlightuserdata(s, fp); return 1; }
void ProfileManager::archive(ProfileManager *p) { fs::path profilepath = broadmask_root(); if (!fs::is_directory(profilepath)) { fs::create_directories(profilepath); } fs::path datapath (profilepath / kProfileManagerFile); ofstream ofs (datapath.string().c_str()); boost::archive::text_oarchive oa(ofs); try { oa << *p; } catch (exception& e) { cerr << "[BroadMask] Could not store ProfileManager: " << e.what() << endl; } }
void log_write(Tox *tox, int fid, const uint8_t *message, uint16_t length, _Bool self) { if(!logging_enabled) { return; } uint8_t path[512], *p; uint8_t name[TOX_MAX_NAME_LENGTH]; int namelen; uint8_t client_id[TOX_CLIENT_ID_SIZE]; FILE *file; p = path + datapath(path); tox_get_client_id(tox, fid, client_id); cid_to_string(p, client_id); p += TOX_CLIENT_ID_SIZE * 2; strcpy((char*)p, ".txt"); file = fopen((char*)path, "ab"); if(file) { time_t rawtime; time(&rawtime); if(self) { namelen = tox_get_self_name(tox, name); } else if((namelen = tox_get_name(tox, fid, name)) == -1) { //error reading name namelen = 0; } struct { uint64_t time; uint16_t namelen, length; uint8_t flags, zeroes[3]; } header = { .time = rawtime, .namelen = namelen, .length = length, .flags = self, }; fwrite(&header, sizeof(header), 1, file); fwrite(name, namelen, 1, file); fwrite(message, length, 1, file); fclose(file); } }
int trap_SaveFile(lua_State *s) { FILE *f; int len; const char *path, *data, *fullpath; trap_args(s, "SaveFile", "ssi", &path, &data, &len); fullpath = datapath(path); f = fopen(fullpath, "wb"); if (f == NULL) FATAL("Failed to write to data file: %s", fullpath); if (len == 0) len = strlen(data); fwrite(data, 1, len, f); fclose(f); return 0; }
void log_write(Tox *tox, int fid, const uint8_t *message, uint16_t length, _Bool author, uint8_t msg_type) { if(!logging_enabled) { return; } uint8_t path[512], *p; uint8_t name[TOX_MAX_NAME_LENGTH]; int namelen; FILE *file; p = path + datapath(path); int len = log_file_name(p, sizeof(path) - (p - path), tox, fid); if (len == -1) return; p += len; file = fopen((char*)path, "ab"); if(file) { time_t rawtime; time(&rawtime); if(author) { namelen = tox_get_self_name(tox, name); } else if((namelen = tox_get_name(tox, fid, name)) == -1) { //error reading name namelen = 0; } LOG_FILE_MSG_HEADER header = { .time = rawtime, .namelen = namelen, .length = length, .flags = author, .msg_type = msg_type, }; fwrite(&header, sizeof(header), 1, file); fwrite(name, namelen, 1, file); fwrite(message, length, 1, file); fclose(file); } }
ProfileManager* ProfileManager::unarchive() { ProfileManager *pm = new ProfileManager(); fs::path profilepath = broadmask_root(); fs::path datapath (profilepath / kProfileManagerFile); if (fs::is_regular_file(datapath)) { std::ifstream ifs(datapath.string().c_str(), std::ios::in); boost::archive::text_iarchive ia(ifs); try { ia >> *pm; } catch (exception& e) { cout << e.what() << endl; } } return pm; }
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { char *envname = NULL; char *dirname = NULL; char *filename = NULL; char *suffix = NULL; char *fname = NULL; if( nrhs != 4 ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if( ! mtlb_get_string( prhs[0], &envname ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if( ! mtlb_get_string( prhs[1], &dirname ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if( ! mtlb_get_string( prhs[2], &filename ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if( ! mtlb_get_string( prhs[3], &suffix ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } fname = datapath( envname, dirname, filename, suffix ); plhs[0] = mxCreateString( fname ); if( fname != (char *) NULL ) { free( fname ); } }
void MapLoader::loadMapObj() { DataLibrary* datalibrary = DataLibrary::getSingletonPtr(); Terrain* terrain = Terrain::getSingletonPtr(); std::string datapath("GameData/BattleData/MapData/MapObjModleInfo"); std::vector<std::string> childlist; childlist = datalibrary->getChildList(datapath); if(childlist.size()>0) { for(unsigned int n = 0; n < childlist.size(); n++) { std::string meshname; int x,y,dir; datalibrary->getData(datapath + std::string("/") + childlist[n] + std::string("/Mesh"),meshname); datalibrary->getData(datapath + std::string("/") +childlist[n] + std::string("/GridX"),x); datalibrary->getData(datapath + std::string("/") +childlist[n] + std::string("/GridY"),y); datalibrary->getData(datapath + std::string("/") +childlist[n] + std::string("/Direction"),dir); int index; index = terrain->createMapObj(x,y,meshname, dir); datalibrary->setData(datapath + std::string("/") + childlist[n] + std::string("/Index"),index); } } datapath = "GameData/BattleData/MapData/MapParticleInfo"; childlist = datalibrary->getChildList(datapath); if(childlist.size()>0) { for(unsigned int n = 0; n < childlist.size(); n++) { std::string particlename; int x,y; datalibrary->getData(datapath + std::string("/") + childlist[n] + std::string("/Particle"),particlename); datalibrary->getData(datapath + std::string("/") +childlist[n] + std::string("/GridX"),x); datalibrary->getData(datapath + std::string("/") +childlist[n] + std::string("/GridY"),y); int index; index = terrain->createMapParticle(x,y,particlename); datalibrary->setData(datapath + std::string("/") + childlist[n] + std::string("/Index"),index); } } }
static void write_save(Tox *tox) { void *data; uint32_t size; uint8_t path_tmp[512], path_real[512], *p; FILE *file; size = tox_size(tox); data = malloc(size); tox_save(tox, data); p = path_real + datapath(path_real); memcpy(p, "tox_save", sizeof("tox_save")); unsigned int path_len = (p - path_real) + sizeof("tox_save"); memcpy(path_tmp, path_real, path_len); memcpy(path_tmp + (path_len - 1), ".tmp", sizeof(".tmp")); file = fopen((char*)path_tmp, "wb"); if(file) { fwrite(data, size, 1, file); flush_file(file); fclose(file); if (rename((char*)path_tmp, (char*)path_real) != 0) { debug("Failed to rename file. %s to %s deleting and trying again\n", path_tmp, path_real); remove((const char *)path_real); if (rename((char*)path_tmp, (char*)path_real) != 0) { debug("Saving Failed\n"); } else { debug("Saved data\n"); } } else { debug("Saved data\n"); } } free(data); }
static void load_inifile(dictionary * d) { const char *reportdir = reportpath(); const char *datadir = datapath(); const char *basedir = basepath(); const char *str; assert(d); str = iniparser_getstring(d, "eressea:base", basedir); if (str != basedir) { set_basepath(str); } str = iniparser_getstring(d, "eressea:report", reportdir); if (str != reportdir) { set_reportpath(str); } str = iniparser_getstring(d, "eressea:data", datadir); if (str != datadir) { set_datapath(str); } lomem = iniparser_getint(d, "eressea:lomem", lomem) ? 1 : 0; str = iniparser_getstring(d, "eressea:encoding", NULL); if (str && (_strcmpl(str, "utf8") == 0 || _strcmpl(str, "utf-8") == 0)) { enc_gamedata = ENCODING_UTF8; } verbosity = iniparser_getint(d, "eressea:verbose", 2); battledebug = iniparser_getint(d, "eressea:debug", battledebug) ? 1 : 0; str = iniparser_getstring(d, "eressea:locales", "de,en"); make_locales(str); if (global.inifile) iniparser_freedict(global.inifile); global.inifile = d; }
void theme_load(char loadtheme) { // Update the settings dropdown UI dropdown_theme.selected = loadtheme; theme = loadtheme; // ==== Default theme ==== //---- Main chat area ---- COLOR_MAIN_BACKGROUND = COLOR_PROC(0xffffff); COLOR_MAIN_TEXT = COLOR_PROC(0x333333); COLOR_MAIN_CHATTEXT = COLOR_PROC(0x000000); COLOR_MAIN_SUBTEXT = COLOR_PROC(0x414141); COLOR_MAIN_ACTIONTEXT = COLOR_PROC(0x4e4ec8); COLOR_MAIN_QUOTETEXT = COLOR_PROC(0x008000); COLOR_MAIN_URLTEXT = COLOR_PROC(0x001fff); COLOR_MAIN_HINTTEXT = COLOR_PROC(0x969696); //---- Friend list header and bottom-left buttons ---- COLOR_MENU_BACKGROUND = COLOR_PROC(0x1c1c1c); COLOR_MENU_TEXT = COLOR_MAIN_BACKGROUND; COLOR_MENU_SUBTEXT = COLOR_PROC(0xd1d1d1); COLOR_MENU_HOVER_BACKGROUND = COLOR_PROC(0x282828); COLOR_MENU_ACTIVE_BACKGROUND = COLOR_PROC(0x414141); COLOR_MENU_ACTIVE_TEXT = COLOR_MAIN_BACKGROUND; //---- Friend list ---- COLOR_LIST_BACKGROUND = COLOR_PROC(0x414141); COLOR_LIST_HOVER_BACKGROUND = COLOR_PROC(0x505050); COLOR_LIST_TEXT = COLOR_MENU_TEXT; COLOR_LIST_SUBTEXT = COLOR_MENU_SUBTEXT; //---- Groupchat user list and title ---- COLOR_GROUP_SELF = COLOR_PROC(0x6bc260); COLOR_GROUP_PEER = COLOR_MAIN_HINTTEXT; COLOR_GROUP_AUDIO = COLOR_PROC(0xc84e4e); COLOR_GROUP_MUTED = COLOR_MAIN_ACTIONTEXT; //---- Text selection ---- COLOR_SELECTION_BACKGROUND = COLOR_MAIN_TEXT; COLOR_SELECTION_TEXT = COLOR_MAIN_BACKGROUND; //---- Inputs, dropdowns & tooltips ---- COLOR_EDGE_NORMAL = COLOR_PROC(0xc0c0c0); COLOR_EDGE_HOVER = COLOR_PROC(0x969696); COLOR_EDGE_ACTIVE = COLOR_PROC(0x4ea6ea); COLOR_ACTIVEOPTION_BACKGROUND = COLOR_PROC(0xd1d1d1); COLOR_ACTIVEOPTION_TEXT = COLOR_MAIN_TEXT; //---- Auxiliary style (for elements in the friendslist) ---- COLOR_AUX_BACKGROUND = COLOR_PROC(0x313131); COLOR_AUX_EDGE_NORMAL = COLOR_AUX_BACKGROUND; COLOR_AUX_EDGE_HOVER = COLOR_PROC(0x999999); COLOR_AUX_EDGE_ACTIVE = COLOR_PROC(0x1A73B7); COLOR_AUX_TEXT = COLOR_LIST_TEXT; COLOR_AUX_ACTIVEOPTION_BACKGROUND = COLOR_LIST_HOVER_BACKGROUND; COLOR_AUX_ACTIVEOPTION_TEXT = COLOR_AUX_TEXT; //---- Status circles ---- COLOR_STATUS_ONLINE = COLOR_PROC(0x6bc260); COLOR_STATUS_AWAY = COLOR_PROC(0xcebf45); COLOR_STATUS_BUSY = COLOR_PROC(0xc84e4e); //---- Buttons ---- COLOR_BUTTON_SUCCESS_BACKGROUND = COLOR_STATUS_ONLINE; COLOR_BUTTON_SUCCESS_TEXT = COLOR_MAIN_BACKGROUND; COLOR_BUTTON_SUCCESS_HOVER_BACKGROUND = COLOR_PROC(0x76d56a); COLOR_BUTTON_SUCCESS_HOVER_TEXT = COLOR_MAIN_BACKGROUND; COLOR_BUTTON_WARNING_BACKGROUND = COLOR_STATUS_AWAY; COLOR_BUTTON_WARNING_TEXT = COLOR_MAIN_BACKGROUND; COLOR_BUTTON_WARNING_HOVER_BACKGROUND = COLOR_PROC(0xe3d24c); COLOR_BUTTON_WARNING_HOVER_TEXT = COLOR_MAIN_BACKGROUND; COLOR_BUTTON_DANGER_BACKGROUND = COLOR_STATUS_BUSY; COLOR_BUTTON_DANGER_TEXT = COLOR_MAIN_BACKGROUND; COLOR_BUTTON_DANGER_HOVER_BACKGROUND = COLOR_PROC(0xdc5656); COLOR_BUTTON_DANGER_HOVER_TEXT = COLOR_MAIN_BACKGROUND; COLOR_BUTTON_DISABLED_BACKGROUND = COLOR_PROC(0xd1d1d1); COLOR_BUTTON_DISABLED_TEXT = COLOR_MAIN_BACKGROUND; COLOR_BUTTON_DISABLED_TRANSFER = COLOR_LIST_BACKGROUND; COLOR_BUTTON_INPROGRESS_BACKGROUND = COLOR_PROC(0x4ea6ea); COLOR_BUTTON_INPROGRESS_TEXT = COLOR_MAIN_BACKGROUND; switch (loadtheme) { case THEME_DARK: COLOR_MAIN_BACKGROUND = COLOR_PROC(0x333333); COLOR_MAIN_TEXT = COLOR_PROC(0xdfdfdf); COLOR_MAIN_CHATTEXT = COLOR_PROC(0xffffff); COLOR_MAIN_SUBTEXT = COLOR_PROC(0xbbbbbb); COLOR_MAIN_ACTIONTEXT = COLOR_PROC(0x27a9bc); COLOR_MAIN_URLTEXT = COLOR_MAIN_ACTIONTEXT; COLOR_MAIN_QUOTETEXT = COLOR_PROC(0x55b317); COLOR_LIST_BACKGROUND = COLOR_PROC(0x222222); COLOR_LIST_HOVER_BACKGROUND = COLOR_PROC(0x151515); COLOR_MENU_BACKGROUND = COLOR_PROC(0x171717); COLOR_MENU_HOVER_BACKGROUND = COLOR_LIST_HOVER_BACKGROUND; COLOR_MENU_ACTIVE_BACKGROUND = COLOR_LIST_BACKGROUND; COLOR_SELECTION_BACKGROUND = COLOR_MAIN_TEXT; COLOR_SELECTION_TEXT = COLOR_MAIN_BACKGROUND; COLOR_GROUP_MUTED = COLOR_MAIN_URLTEXT; COLOR_EDGE_NORMAL = COLOR_PROC(0x555555); COLOR_EDGE_ACTIVE = COLOR_PROC(0x228888); COLOR_EDGE_HOVER = COLOR_PROC(0x999999); COLOR_ACTIVEOPTION_BACKGROUND = COLOR_PROC(0x228888); COLOR_ACTIVEOPTION_TEXT = COLOR_MAIN_TEXT; COLOR_AUX_BACKGROUND = COLOR_MENU_BACKGROUND; COLOR_AUX_EDGE_NORMAL = COLOR_AUX_BACKGROUND; COLOR_AUX_EDGE_ACTIVE = COLOR_EDGE_ACTIVE; COLOR_AUX_ACTIVEOPTION_BACKGROUND = COLOR_ACTIVEOPTION_BACKGROUND; COLOR_MENU_ACTIVE_TEXT = COLOR_MAIN_TEXT; COLOR_BUTTON_SUCCESS_BACKGROUND = COLOR_PROC(0x414141); COLOR_BUTTON_SUCCESS_TEXT = COLOR_PROC(0x33a63d); COLOR_BUTTON_SUCCESS_HOVER_BACKGROUND = COLOR_PROC(0x455147); COLOR_BUTTON_SUCCESS_HOVER_TEXT = COLOR_PROC(0x6eff3a); COLOR_BUTTON_WARNING_BACKGROUND = COLOR_PROC(0x414141); COLOR_BUTTON_WARNING_TEXT = COLOR_PROC(0xbd9e22); COLOR_BUTTON_WARNING_HOVER_BACKGROUND = COLOR_PROC(0x4c493c); COLOR_BUTTON_WARNING_HOVER_TEXT = COLOR_PROC(0xff8d2a); COLOR_BUTTON_DANGER_BACKGROUND = COLOR_PROC(0x414141); COLOR_BUTTON_DANGER_TEXT = COLOR_PROC(0xbd2525); COLOR_BUTTON_DANGER_HOVER_BACKGROUND = COLOR_PROC(0x513939); COLOR_BUTTON_DANGER_HOVER_TEXT = COLOR_PROC(0xfa2626); COLOR_BUTTON_DISABLED_BACKGROUND = COLOR_PROC(0x414141); COLOR_BUTTON_DISABLED_TEXT = COLOR_MAIN_TEXT; COLOR_BUTTON_DISABLED_TRANSFER = COLOR_BUTTON_DISABLED_TEXT; COLOR_BUTTON_INPROGRESS_BACKGROUND = COLOR_BUTTON_DISABLED_BACKGROUND; COLOR_BUTTON_INPROGRESS_TEXT = COLOR_MAIN_URLTEXT; break; case THEME_LIGHT: COLOR_LIST_BACKGROUND = COLOR_PROC(0xf0f0f0); COLOR_LIST_HOVER_BACKGROUND = COLOR_PROC(0xe0e0e0); COLOR_LIST_TEXT = COLOR_MAIN_TEXT; COLOR_LIST_SUBTEXT = COLOR_MAIN_SUBTEXT; COLOR_MENU_BACKGROUND = COLOR_PROC(0xf0f0f0); COLOR_MENU_HOVER_BACKGROUND = COLOR_PROC(0xe0e0e0); COLOR_MENU_ACTIVE_BACKGROUND = COLOR_PROC(0x555555); COLOR_MENU_TEXT = COLOR_PROC(0x555555); COLOR_MENU_ACTIVE_TEXT = COLOR_PROC(0xffffff); COLOR_MENU_SUBTEXT = COLOR_PROC(0x414141); COLOR_EDGE_NORMAL = COLOR_PROC(0xc0c0c0); COLOR_EDGE_ACTIVE = COLOR_MAIN_URLTEXT; COLOR_EDGE_HOVER = COLOR_PROC(0x707070); COLOR_ACTIVEOPTION_BACKGROUND = COLOR_PROC(0xddeeff); COLOR_ACTIVEOPTION_TEXT = COLOR_MAIN_TEXT; COLOR_AUX_BACKGROUND = COLOR_PROC(0xe0e0e0); COLOR_AUX_EDGE_NORMAL = COLOR_AUX_BACKGROUND; COLOR_AUX_EDGE_HOVER = COLOR_PROC(0x999999); COLOR_AUX_EDGE_ACTIVE = COLOR_EDGE_ACTIVE; COLOR_AUX_TEXT = COLOR_LIST_TEXT; COLOR_AUX_ACTIVEOPTION_BACKGROUND = COLOR_LIST_HOVER_BACKGROUND; COLOR_AUX_ACTIVEOPTION_TEXT = COLOR_AUX_TEXT; break; case THEME_HIGHCONTRAST: COLOR_MAIN_BACKGROUND = COLOR_PROC(0xffffff); COLOR_MAIN_TEXT = COLOR_PROC(0x000001); COLOR_MAIN_CHATTEXT = COLOR_MAIN_TEXT; COLOR_MAIN_SUBTEXT = COLOR_MAIN_TEXT; COLOR_MAIN_ACTIONTEXT = COLOR_PROC(0x0000ff); COLOR_MAIN_QUOTETEXT = COLOR_PROC(0x00ff00); COLOR_MAIN_URLTEXT = COLOR_MAIN_ACTIONTEXT; COLOR_MAIN_HINTTEXT = COLOR_MAIN_TEXT; COLOR_MENU_BACKGROUND = COLOR_MAIN_BACKGROUND; COLOR_MENU_TEXT = COLOR_MAIN_TEXT; COLOR_MENU_SUBTEXT = COLOR_MAIN_TEXT; COLOR_MENU_HOVER_BACKGROUND = COLOR_MAIN_BACKGROUND; COLOR_MENU_ACTIVE_BACKGROUND = COLOR_MAIN_TEXT; COLOR_MENU_ACTIVE_TEXT = COLOR_MAIN_BACKGROUND; COLOR_LIST_BACKGROUND = COLOR_PROC(0x444444); COLOR_LIST_HOVER_BACKGROUND = COLOR_MAIN_TEXT; COLOR_LIST_TEXT = COLOR_MAIN_BACKGROUND; COLOR_LIST_SUBTEXT = COLOR_MAIN_BACKGROUND; COLOR_GROUP_SELF = COLOR_PROC(0x00ff00); COLOR_GROUP_PEER = COLOR_MAIN_HINTTEXT; COLOR_GROUP_AUDIO = COLOR_PROC(0xff0000); COLOR_GROUP_MUTED = COLOR_MAIN_URLTEXT; COLOR_SELECTION_BACKGROUND = COLOR_MAIN_TEXT; COLOR_SELECTION_TEXT = COLOR_MAIN_BACKGROUND; COLOR_EDGE_NORMAL = COLOR_MAIN_TEXT; COLOR_EDGE_ACTIVE = COLOR_MAIN_TEXT; COLOR_EDGE_HOVER = COLOR_MAIN_TEXT; COLOR_ACTIVEOPTION_BACKGROUND = COLOR_MAIN_TEXT; COLOR_ACTIVEOPTION_TEXT = COLOR_MAIN_BACKGROUND; COLOR_STATUS_ONLINE = COLOR_PROC(0x00ff00); COLOR_STATUS_AWAY = COLOR_PROC(0xffff00); COLOR_STATUS_BUSY = COLOR_PROC(0xff0000); COLOR_BUTTON_SUCCESS_BACKGROUND = COLOR_PROC(0x00ff00); COLOR_BUTTON_SUCCESS_TEXT = COLOR_MAIN_BACKGROUND; COLOR_BUTTON_SUCCESS_HOVER_BACKGROUND = COLOR_PROC(0x00ff00); COLOR_BUTTON_SUCCESS_HOVER_TEXT = COLOR_MAIN_BACKGROUND; COLOR_BUTTON_WARNING_BACKGROUND = COLOR_PROC(0xffff00); COLOR_BUTTON_WARNING_TEXT = COLOR_MAIN_BACKGROUND; COLOR_BUTTON_WARNING_HOVER_BACKGROUND = COLOR_PROC(0xffff00); COLOR_BUTTON_WARNING_HOVER_TEXT = COLOR_MAIN_BACKGROUND; COLOR_BUTTON_DANGER_BACKGROUND = COLOR_PROC(0xff0000); COLOR_BUTTON_DANGER_TEXT = COLOR_MAIN_BACKGROUND; COLOR_BUTTON_DANGER_HOVER_BACKGROUND = COLOR_PROC(0xff0000); COLOR_BUTTON_DANGER_HOVER_TEXT = COLOR_MAIN_BACKGROUND; COLOR_BUTTON_DISABLED_BACKGROUND = COLOR_PROC(0x444444); COLOR_BUTTON_DISABLED_TEXT = COLOR_MAIN_TEXT; COLOR_BUTTON_DISABLED_TRANSFER = COLOR_MAIN_BACKGROUND; COLOR_BUTTON_INPROGRESS_TEXT = COLOR_BUTTON_DISABLED_TEXT; COLOR_BUTTON_INPROGRESS_BACKGROUND = COLOR_PROC(0x00ffff); COLOR_AUX_BACKGROUND = COLOR_MAIN_BACKGROUND; COLOR_AUX_EDGE_NORMAL = COLOR_EDGE_NORMAL; COLOR_AUX_EDGE_HOVER = COLOR_EDGE_NORMAL; COLOR_AUX_EDGE_ACTIVE = COLOR_EDGE_ACTIVE; COLOR_AUX_TEXT = COLOR_MAIN_TEXT; COLOR_AUX_ACTIVEOPTION_BACKGROUND = COLOR_ACTIVEOPTION_BACKGROUND; COLOR_AUX_ACTIVEOPTION_TEXT = COLOR_ACTIVEOPTION_TEXT; break; case THEME_CUSTOM: { uint8_t themepath[1024]; int len = datapath(themepath); const char *s = "utox_theme.ini"; int size = sizeof("utox_theme.ini"); if (len + size > 1024) { puts("datapath too long, abandoning ship!"); break; } memcpy(themepath + len, s, size); read_custom_theme((const char *)themepath); } } status_color[0] = COLOR_STATUS_ONLINE; status_color[1] = COLOR_STATUS_AWAY; status_color[2] = COLOR_STATUS_BUSY; status_color[3] = COLOR_STATUS_BUSY; }
std::string Support::datapath(const std::string& file) { const std::string s = datapath() + file; return s; }
void log_read(Tox *tox, int fid) { uint8_t path[512], *p; FILE *file; p = path + datapath(path); int len = log_file_name(p, sizeof(path) - (p - path), tox, fid); if (len == -1) { debug("Error getting log file name for friend %d\n", fid); return; } file = fopen((char*)path, "rb"); if(!file) { debug("File not found (%s)\n", path); p = path + datapath_old(path); len = log_file_name(p, sizeof(path) - (p - path), tox, fid); if (len == -1) { debug("Error getting log file name for friend %d\n", fid); return; } file = fopen((char*) path, "rb"); if (!file) { debug("File not found (%s)\n", path); return; } } LOG_FILE_MSG_HEADER header; off_t rewinds[MAX_BACKLOG_MESSAGES] = {}; size_t records_count = 0; /* todo: some checks to avoid crashes with corrupted log files */ /* first find the last MAX_BACKLOG_MESSAGES messages in the log */ while(1 == fread(&header, sizeof(LOG_FILE_MSG_HEADER), 1, file)) { fseeko(file, header.namelen + header.length, SEEK_CUR); rewinds[records_count % countof(rewinds)] = (off_t) sizeof(LOG_FILE_MSG_HEADER) + header.namelen + header.length; records_count++; } if(ferror(file) || !feof(file)) { // TODO: consider removing or truncating the log file. // If !feof() this means that the file has an incomplete record, // which would prevent it from loading forever, even though // new records will keep being appended as usual. debug("Log read error (%s)\n", path); fclose(file); return; } // Backtrack to read last MAX_BACKLOG_MESSAGES in full. off_t rewind = 0; MSG_IDX i; for(i = 0; (i < records_count) && (i < countof(rewinds)); i++) { rewind += rewinds[i]; } fseeko(file, -rewind, SEEK_CUR); MSG_DATA *m = &friend[fid].msg; m->data = malloc(sizeof(void*) * i); m->n = 0; /* add the messages */ while((0 < i) && (1 == fread(&header, sizeof(LOG_FILE_MSG_HEADER), 1, file))) { i--; // Skip unused friend name recorded at the time. fseeko(file, header.namelen, SEEK_CUR); MESSAGE *msg = NULL; switch(header.msg_type) { case LOG_FILE_MSG_TYPE_ACTION: { msg = malloc(sizeof(MESSAGE) + header.length); msg->msg_type = MSG_TYPE_ACTION_TEXT; break; } case LOG_FILE_MSG_TYPE_TEXT: { msg = malloc(sizeof(MESSAGE) + header.length); msg->msg_type = MSG_TYPE_TEXT; break; } default: { debug("Unknown backlog message type(%d), skipping.\n", (int)header.msg_type); fseeko(file, header.length, SEEK_CUR); continue; } } // Read text message. msg->author = header.flags & 1; msg->length = header.length; if(1 != fread(msg->msg, msg->length, 1, file)) { debug("Log read error (%s)\n", path); fclose(file); return; } struct tm *ti; time_t rawtime = header.time; ti = localtime(&rawtime); msg->time = ti->tm_hour * 60 + ti->tm_min; m->data[m->n++] = msg; debug("loaded backlog: %d: %.*s\n", fid, msg->length, msg->msg); } fclose(file); }
static _Bool load_save(Tox *tox) { { uint8_t path[512], *p; uint32_t size; p = path + datapath(path); strcpy((char*)p, "tox_save"); void *data = file_raw((char*)path, &size); if(!data) { p = path + datapath_old(path); strcpy((char*)p, "tox_save"); data = file_raw((char*)path, &size); if (!data) { data = file_raw("tox_save", &size); if(!data) { return 0; } } } tox_load(tox, data, size); free(data); } friends = tox_count_friendlist(tox); uint32_t i = 0; while(i != friends) { int size; FRIEND *f = &friend[i]; uint8_t name[TOX_MAX_NAME_LENGTH]; f->msg.scroll = 1.0; tox_get_client_id(tox, i, f->cid); size = tox_get_name(tox, i, name); friend_setname(f, name, size); size = tox_get_status_message_size(tox, i); f->status_message = malloc(size); tox_get_status_message(tox, i, f->status_message, size); f->status_length = size; log_read(tox, i); i++; } self.name_length = tox_get_self_name(tox, self.name); self.statusmsg_length = tox_get_self_status_message_size(tox); self.statusmsg = malloc(self.statusmsg_length); tox_get_self_status_message(tox, self.statusmsg, self.statusmsg_length); self.status = tox_get_self_user_status(tox); return 1; }
QString Path::images() { return datapath() + "images/"; }
QString Path::thumbnails() { return datapath() + "images/thumbnails/"; }
QString Path::saves() { return datapath() + "saves/"; }
void pyne::Material::from_hdf5(char * fchar, char * dchar, int row, int protocol) { std::string filename (fchar); std::string datapath (dchar); from_hdf5(filename, datapath, row, protocol); };