void CaMuleExternalConnector::SaveConfigFile() { if (!wxFileName::DirExists(GetConfigDir())) { wxFileName::Mkdir(GetConfigDir()); } if (!m_configFile) { m_configFile = new CECFileConfig(m_configFileName); } if (m_configFile) { m_configFile->Write(wxT("/Locale"), m_language); m_configFile->Write(wxT("/EC/Host"), m_host); m_configFile->Write(wxT("/EC/Port"), m_port); m_configFile->WriteHash(wxT("/EC/Password"), m_password); } }
void WorkspaceWork::AddFile(ADDFILE af) { String active = GetActivePackage(); if(active.IsEmpty()) return; FileSel *fs = &OutputFs(); RealizeDirectory(GetLocalDir()); switch(af) { case PACKAGE_FILE: fs = &BasedSourceFs(); fs->BaseDir(GetFileFolder(PackagePathA(active))); break; case ANY_FILE: fs = &AnySourceFs(); break; case OUTPUT_FILE: fs->ActiveDir(GetOutputDir()); break; case CONFIG_FILE: fs->ActiveDir(GetConfigDir()); break; case HOME_FILE: fs->ActiveDir(GetHomeDirectory()); break; case LOCAL_FILE: fs->ActiveDir(GetLocalDir()); break; default: ; // GCC warns otherwise } if(!fs->ExecuteOpen("Add files to package..")) return; int fci = filelist.GetCursor(); int cs = filelist.GetSbPos(); int ci = fci >= 0 && fci < fileindex.GetCount() ? fileindex[fci] : -1; for(int i = 0; i < fs->GetCount(); i++) { Package::File& f = ci >= 0 ? actual.file.Insert(ci++) : actual.file.Add(); f = (*fs)[i]; f.readonly = fs->GetReadOnly(); } SaveLoadPackage(false); filelist.SetSbPos(cs); filelist.SetCursor(fci >= 0 ? fci : filelist.GetCount() - 1); FileSelected(); }
ADVBConfig::ADVBConfig() : config(AString(DEFAULTCONFDIR).CatPath("dvb"), false), defaults(20, &AString::DeleteString), webresponse(false) { static const struct { const char *name; const char *value; } __defaults[] = { {"prehandle", "2"}, {"posthandle", "3"}, {"pri", "0"}, {"dir", ""}, {"h264crf", "17"}, {"maxvideorate", "2000k"}, {"aacbitrate", "160k"}, {"mp3bitrate", "160k"}, {"copyvideo", "-vcodec copy"}, {"copyaudio", "-acodec copy"}, {"mp3audio", "-acodec mp3 -b:a {conf:mp3bitrate}"}, {"h264preset", "veryfast"}, {"h264bufsize", "3000k"}, {"videodeinterlace", "yadif"}, {"videofilter", "-filter:v {conf:videodeinterlace}"}, {"filters", "{conf:videofilter} {conf:audiofilter}"}, {"encodeflags", "-movflags +faststart"}, {"h264video", "-vcodec libx264 -preset {conf:h264preset} -crf {conf:h264crf} -maxrate {conf:maxvideorate} -bufsize {conf:h264bufsize} {conf:encodeflags} {conf:filters}"}, {"aacaudio", "-acodec libfdk_aac -b:a {conf:aacbitrate}"}, {"encodecopy", "{conf:copyvideo} {conf:mp3audio}"}, {"encodeh264", "{conf:h264video} {conf:aacaudio}"}, {"encodeargs", "{conf:encodeh264}"}, {"encodeaudioonlyargs", "{conf:mp3audio}"}, }; uint_t i; for (i = 0; i < NUMBEROF(__defaults); i++) { defaults.Insert(__defaults[i].name, (uptr_t)new AString(__defaults[i].value)); } CreateDirectory(GetConfigDir()); CreateDirectory(GetDataDir()); CreateDirectory(GetLogDir()); CreateDirectory(GetRecordingsStorageDir()); CreateDirectory(GetRecordingsDir()); CreateDirectory(GetTempDir()); if (CommitScheduling()) { AList users; AString dir; ListUsers(users); const AString *user = AString::Cast(users.First()); while (user) { if (((dir = GetRecordingsDir(*user)).Valid()) && (dir.Pos("{") < 0)) CreateDirectory(dir); if (((dir = GetRecordingsArchiveDir(*user)).Valid()) && (dir.Pos("{") < 0)) CreateDirectory(dir); user = user->Next(); } } }
void CreateReposDlg::CheckValues() { wxASSERT(0 != m_checkBdbLogKeep); wxASSERT(0 != m_checkBdbTxnNoSync); wxASSERT(0 != m_buttonOk); wxASSERT(0 != m_textFilename); wxString msg; bool valid=true; bool isBdb = TYPE_BDB == GetType(); m_checkBdbLogKeep->Enable(isBdb); m_checkBdbTxnNoSync->Enable(isBdb); // Now check whether we can proceed wxString name(GetName()); wxString dir(GetDir()); wxString configDir(GetConfigDir()); wxString filename(GetFilename()); if (!m->svnadminAvailable) { valid = false; msg = _("svnadmin could not be found"); } else if (dir.IsEmpty() || !::IsValidDir(dir)) { valid = false; msg = _("Select an existing directory for the repository"); } else if (name.IsEmpty()) { valid = false; msg = _("Enter a name for the repository"); } else if (::IsValidDir(filename)) { valid = false; msg = _("A directory of this name exists already"); } else if (::wxFileExists(filename)) { valid = false; msg = _("A file of this name exists already"); } else if (!configDir.IsEmpty() && !::IsValidDir(configDir)) { valid = false; msg = _("The configuration directory does not exist"); } m_textFilename->SetValue(filename); m_staticWarning->SetLabel(msg); m_buttonOk->Enable(valid); }
char *GetTemplateDirectory() { char *path = (char *)smal(MAXPATHLEN); GetConfigDir(path); strcat(path, ".templates"); mkdir(path, 0xffffffff); return path; }
wxString CamulewebApp::SetLocale(const wxString& language) { wxString lang = CaMuleExternalConnector::SetLocale(language); // will call setlocale() for us // SetLocale() may indeed return an empty string, when no locale has been selected yet and // no locale change was requested, or, in the worst case, if the last locale change didn't succeed. if (!lang.IsEmpty()) { DebugShow(wxT("*** Language set to: ") + lang + wxT(" ***\n")); #ifdef ENABLE_NLS wxString domain = wxT("amuleweb-") + m_TemplateName; Unicode2CharBuf domainBuf = unicode2char(domain); const char *c_domain = (const char *)domainBuf; // Try to find a message catalog // First look in ~/.aMule/webserver/<template>, but only if a local template was used wxString dir; if (m_localTemplate) { dir = JoinPaths(JoinPaths(JoinPaths(GetConfigDir(), wxT("webserver")), m_TemplateName), wxT("locale")); DebugShow(wxT("looking for message catalogs in ") + dir + wxT("... ")); } if (!m_localTemplate || !DirHasMessageCatalog(dir, lang, domain)) { if (m_localTemplate) { DebugShow(wxT("no\n")); } #if defined __WXMAC__ || defined __WXMSW__ // on Mac, the bundle may be tried, too dir = wxStandardPaths::Get().GetDataDir(); #elif defined(__UNIX__) dir = JoinPaths(static_cast<wxStandardPaths&>(wxStandardPaths::Get()).GetInstallPrefix(), JoinPaths(wxT("share"), wxT("locale"))); #endif DebugShow(wxT("looking for message catalogs in ") + dir + wxT("... ")); if (!DirHasMessageCatalog(dir, lang, domain)) { DebugShow(wxT("no\n")); dir = wxEmptyString; } else { DebugShow(wxT("yes\n")); } } else { DebugShow(wxT("yes\n")); } // If we found something, then use it otherwise it may still be present at the system default location if (!dir.IsEmpty()) { Unicode2CharBuf buffer = unicode2char(dir); const char *c_dir = (const char *)buffer; bindtextdomain(c_domain, c_dir); } // We need to have the returned messages in UTF-8 bind_textdomain_codeset(c_domain, "UTF-8"); // And finally select the message catalog textdomain(c_domain); #endif /* ENABLE_NLS */ } return lang; }
bool CamuleDlg::Check_and_Init_Skin() { bool ret = true; wxString skinFileName(thePrefs::GetSkin()); if (skinFileName.IsEmpty() || skinFileName.IsSameAs(_("- default -"))) { return false; } wxString userDir(JoinPaths(GetConfigDir(), wxT("skins")) + wxFileName::GetPathSeparator()); wxStandardPathsBase &spb(wxStandardPaths::Get()); #ifdef __WINDOWS__ wxString dataDir(spb.GetPluginsDir()); #elif defined(__WXMAC__) wxString dataDir(spb.GetDataDir()); #else wxString dataDir(spb.GetDataDir().BeforeLast(wxT('/')) + wxT("/amule")); #endif wxString systemDir(JoinPaths(dataDir,wxT("skins")) + wxFileName::GetPathSeparator()); skinFileName.Replace(wxT("User:"******"System:"), systemDir ); m_skinFileName.Assign(skinFileName); if (!m_skinFileName.FileExists()) { AddLogLineC(CFormat( _("Skin directory '%s' does not exist")) % skinFileName ); ret = false; } else if (!m_skinFileName.IsFileReadable()) { AddLogLineC(CFormat( _("WARNING: Unable to open skin file '%s' for read")) % skinFileName); ret = false; } wxFFileInputStream in(m_skinFileName.GetFullPath()); wxZipInputStream zip(in); wxZipEntry *entry; while ((entry = zip.GetNextEntry()) != NULL) { wxZipEntry*& current = cat[entry->GetInternalName()]; delete current; current = entry; } return ret; }
static char *GetConfigFileName() { static char cfg_path[MAXPATHLEN]; char *dir; dir = GetConfigDir(cfg_path); if (dir) { strcat(dir, "settings"); return dir; } else { return NULL; } }
void WorkspaceWork::InsertSpecialMenu(Bar& menu) { bool isaux = IsAux(); menu.Add("Insert any file(s)", THISBACK1(AddFile, ANY_FILE)) .Key(K_SHIFT|K_CTRL_I) .Help("Insert files from anywhere on disk (discouraged in portable packages)"); menu.Add(isaux && GetOutputDir().GetCount(), "Insert output directory file(s)", THISBACK1(AddFile, OUTPUT_FILE)) .Help("Open file selector in output / intermediate directory for current package"); #ifdef PLATFORM_POSIX menu.Add(isaux && GetConfigDir().GetCount(), "Insert config directory file(s)", THISBACK1(AddFile, CONFIG_FILE)) .Help("Open file selector in output / intermediate directory for current package"); #endif menu.Add(isaux, "Insert Local directory file(s)", THISBACK1(AddFile, LOCAL_FILE)) .Help("Open file selector in Local directory for current package"); menu.Add("Insert home directory file(s)", THISBACK1(AddFile, HOME_FILE)) .Help("Open file selector in current user's HOME directory"); }
bool CamulewebApp::GetTemplateDir(const wxString& templateName, wxString& templateDir) { wxString dir; m_localTemplate = false; DebugShow(wxT("looking for template: ") + templateName + wxT("\n")); #ifdef __WXMAC__ CFURLRef amuleBundleUrl; OSStatus status = LSFindApplicationForInfo( kLSUnknownCreator, // This magic string is the bundle identifier in aMule.app's Info.plist CFSTR("org.amule.aMule"), NULL, NULL, &amuleBundleUrl); if (status == noErr && amuleBundleUrl) { CFBundleRef amuleBundle = CFBundleCreate(NULL, amuleBundleUrl); CFRelease(amuleBundleUrl); if (amuleBundle) { CFURLRef webserverDirUrl = CFBundleCopyResourceURL( amuleBundle, CFSTR("webserver"), NULL, NULL); CFRelease(amuleBundle); if (webserverDirUrl) { CFURLRef absoluteURL = CFURLCopyAbsoluteURL(webserverDirUrl); CFRelease(webserverDirUrl); if (absoluteURL) { CFStringRef pathString = CFURLCopyFileSystemPath( absoluteURL, kCFURLPOSIXPathStyle); CFRelease(absoluteURL); #if wxCHECK_VERSION(2, 9, 0) dir = wxCFStringRef(pathString). AsString(wxLocale::GetSystemEncoding()); #else dir = wxMacCFStringHolder(pathString). AsString(wxLocale::GetSystemEncoding()); #endif if (CheckDirForTemplate(dir, templateName)) { templateDir = dir; return true; } } } } } #endif dir = GetConfigDir(wxT("remote.conf")) + wxT("webserver"); if (CheckDirForTemplate(dir, templateName)) { templateDir = dir; m_localTemplate = true; return true; } #ifdef WEBSERVERDIR dir = wxT(WEBSERVERDIR); if (CheckDirForTemplate(dir, templateName)) { templateDir = dir; return true; } #endif dir = wxStandardPaths::Get().GetResourcesDir(); // Returns 'aMule' when we use 'amule' elsewhere #if !defined(__WXMSW__) && !defined(__WXMAC__) dir = dir.BeforeLast(wxFileName::GetPathSeparator()); dir = JoinPaths(dir, wxT("amule")); #endif dir = JoinPaths(dir, wxT("webserver")); if (CheckDirForTemplate(dir, templateName)) { templateDir = dir; return true; } // template not found. reverting to default const wxChar* const defaultTemplateName = wxT("default"); if ( templateName == defaultTemplateName ) { return false; } Show(wxT("Template ") + templateName + wxT(" not found, reverting to default\n\n")); return GetTemplateDir(defaultTemplateName, templateDir); }
string ScoreFile::GetHighScoreFile() { return GetConfigDir() + "scores"; }
/**This is the master parser of the config file, this function basically will figure out what [configuration] functions to call with what arguments from the practically unformatter configuration file**/ void ParseConfigFile(unsigned char *cfile){ FILE *config_file; FILE *test_file; volatile unsigned char tmp_stor=0; unsigned char *tmp,*tmp2,*tmp3; void *tmp_ptr,*tmp2_ptr; unsigned char comments=0; unsigned int i1=0,i2=0; unsigned char got=0; //this is set when a cycle completed successful, if this is 0 at it will give a syntax error unsigned int buf_size; unsigned char use=1; //this is 1 if we actually do a command or 0 if we don't(for commenting and such) unsigned char quotes=0; unsigned char skipping=0; //this is 1 if were to ignore a byte for this "cycle" unsigned char in_it=0; //this is 1 if were in a command yet or 0 if were at the start of the stirng config_file=fopen(cfile,"r"); if(config_file==NULL){panic("Error opening config file\n");} tmp=malloc(1024*64); if(tmp==NULL){panic("Error allocating temporary memory\n");} tmp2=malloc(512); if(tmp2==NULL){panic("Error allocating temporary memory\n");} tmp_ptr=tmp; tmp2_ptr=tmp2; //these store the original pointers so we can free them later.. GetConfigDir(cfile); while(!feof(config_file)){ if(comments==1){skipping=1;i1--;} //parse out comments tmp[i1]=fgetc(config_file); if(skipping==0 && tmp[i1]=='\n'){ tmp[i1]=0; comments=0; quotes=0; in_it=0; } if(skipping==0 && tmp[i1]=='\r'){ tmp[i1]=0; comments=0; quotes=0; in_it=0; } if(skipping==0 && comments==0 && quotes==0 && tmp[i1]==':'){ tmp[i1]=0;in_it=0;} //convert :'s to null termination if(skipping==0 && comments==0 && tmp[i1]=='\"'){ skipping=1; i1--; //do this to remove quotes quotes=quotes^1; //flip flop the quotes thing } if(quotes==0 && skipping==0 && comments==0 && in_it==0 && tmp[i1]==' '){skipping=1;i1--;} //skip this byte if(skipping==0 && comments==0 && in_it==0 && tmp[i1]=='\t'){skipping=1;i1--;} if(skipping==0 && tmp[i1]=='#'){tmp[i1]=0;comments=1; quotes=0;in_it=0; while((tmp_stor!='\r') || (tmp_stor!='\n') || (tmp_stor==0xFF)){ tmp_stor=fgetc(config_file); if(tmp_stor=='\n'){break;} if(tmp_stor=='\r'){break;} if(tmp_stor==0xFF){break;} //printf("bah: %c\n",tmp_stor); //system("pause"); } i1--; comments=0; skipping=0; in_it=1; } if(tmp[i1]==0xFF){tmp[i1]=0;break;} i1++; skipping=0; } //now done with the parsing of comments and new lines //this completely works as expected!! buf_size=i1; //save the size printf("\n\nDebug output for config_files.c\n\n"); //now parse for actual commands!! tmp2=tmp; while(1){ if(tmp2>=(tmp+buf_size)){break;} //if were at the end of the buffer //now then.. add all of our commands/keywords if(strlen(tmp2)==0){got=1;} //these are "this os only" prefixes if(strcmp(tmp2,"unix_only")==0){ #ifndef __unix__ use=0; #endif tmp2=tmp2+strlen(tmp2)+1; //set it to the next command got=1; } if(strcmp(tmp2,"win32_only")==0){ #ifndef WIN32 use=0; #endif tmp2=tmp2+strlen(tmp2)+1; //set it to the next command got=1; } //actual commands/keywords if(strcmp(tmp2,"mem")==0){ tmp2=tmp2+strlen(tmp2)+1; if(use==1){SetMemSize(atoi(tmp2));} //we only actually execute the command if use is 1 got=1; } if(strcmp(tmp2,"load_bios")==0){ tmp2=tmp2+strlen(tmp2)+1; if(use==1){LoadBios(tmp2);} //we only actually execute the command if use is 1 got=1; } if(strcmp(tmp2,"cpu")==0){ tmp2=tmp2+strlen(tmp2)+1; if(use==1){SetCpu(tmp2);} got=1; } if(strcmp(tmp2,"load_bin_file")==0){ tmp2=tmp2+strlen(tmp2)+1; test_file=fopen(tmp2,"r"); if(test_file!=NULL){if(use==1){fclose(test_file);LoadBinFile(tmp2);}got=1;} else{ *tmp_filename='\0'; strcat(tmp_filename,config_dir); printf("config_dir=%s\n",config_dir); strcat(tmp_filename,tmp2); //system("cd"); if(use==1){LoadBinFile(tmp_filename);} got=1; } } if(strcmp(tmp2,"load_com_file")==0){ tmp2=tmp2+strlen(tmp2)+1; test_file=fopen(tmp2,"r"); if(test_file!=NULL){if(use==1){fclose(test_file);LoadComFile(tmp2);}got=1;} else{ *tmp_filename='\0'; strcat(tmp_filename,config_dir); printf("config_dir=%s\n",config_dir); strcat(tmp_filename,tmp2); //system("cd"); if(use==1){LoadComFile(tmp_filename);} got=1; } } if(strcmp(tmp2,"randomize_memory")==0){ Randomize_Memory(); got=1; } if(strcmp(tmp2,"load_device")==0){ tmp2=tmp2+strlen(tmp2)+1; strcpy(tmp_filename,tmp2); tmp3=tmp_filename; tmp3=tmp3+strlen(tmp_filename)-1; if(*tmp3=='*'){ //add the predefined OS specific extension *tmp3=0; #ifdef WIN32 strcat(tmp_filename,"dll"); #else strcat(tmp_filename,"so"); #endif } test_file=fopen(tmp_filename,"r"); if(test_file!=NULL){if(use==1){fclose(test_file);InitExLib(tmp_filename);}got=1;} else{ *tmp_filename='\0'; strcat(tmp_filename,config_dir); printf("config_dir=%s\n",config_dir); strcat(tmp_filename,tmp2); tmp3=tmp_filename; tmp3=tmp3+strlen(tmp_filename)-1; if(*tmp3=='*'){ *tmp3=0; #ifdef WIN32 strcat(tmp_filename,"dll"); #else strcat(tmp_filename,"so"); #endif } //system("cd"); if(use==1){InitExLib(tmp_filename);} got=1; } } if(got==0){printf("Error parsing config file!\nError keyword is ");printf(tmp2);printf("\n");printf("strlen=%i",strlen(tmp2));panic("");} tmp2=tmp2+strlen(tmp2)+1; use=1; got=0; } printf("\n\nNow ending debug output for config_files.c\n\n"); free(tmp_ptr); free(tmp2_ptr); }
bool CaMuleExternalConnector::OnCmdLineParsed(wxCmdLineParser& parser) { if (parser.Found(wxT("version"))) { printf("%s %s\n", m_appname, (const char *)unicode2char(GetMuleVersion())); return false; } if (!parser.Found(wxT("config-file"), &m_configFileName)) { m_configFileName = GetConfigDir() + wxT("remote.conf"); } wxString aMuleConfigFile; if (parser.Found(wxT("create-config-from"), &aMuleConfigFile)) { aMuleConfigFile = FinalizeFilename(aMuleConfigFile); if (!::wxFileExists(aMuleConfigFile)) { fprintf(stderr, "%s\n", (const char *)unicode2char(wxT("FATAL ERROR: File does not exist: ") + aMuleConfigFile)); exit(1); } CECFileConfig aMuleConfig(aMuleConfigFile); LoadAmuleConfig(aMuleConfig); SaveConfigFile(); m_configFile->Flush(); exit(0); } LoadConfigFile(); if ( !parser.Found(wxT("host"), &m_host) ) { if ( m_host.IsEmpty() ) { m_host = wxT("localhost"); } } long port; if (parser.Found(wxT("port"), &port)) { m_port = port; } wxString pass_plain; if (parser.Found(wxT("password"), &pass_plain)) { if (!pass_plain.IsEmpty()) { m_password.Decode(MD5Sum(pass_plain).GetHash()); } else { m_password.Clear(); } } if (parser.Found(wxT("write-config"))) { m_NeedsConfigSave = true; } parser.Found(wxT("locale"), &m_language); if (parser.Found(wxT("help"))) { parser.Usage(); return false; } m_KeepQuiet = parser.Found(wxT("quiet")); m_Verbose = parser.Found(wxT("verbose")); return true; }