Exemple #1
0
    void EntryManager::createEntry(const char * e_name, const char * e_source_path, const char * e_source_folder_name, const char * e_exe_path) {
        if (!isNameFree(e_name)) {
            throw InvalidConfigFileException();
        }
        // Create the entry folder structure
        std::string line = "mkdir ~/" + std::string(e_name);
        std::cout << (line) << std::endl;
        system((line).c_str());
        line += "/drive_c";
        system((line).c_str());
        std::cout << (line) << std::endl;
        std::string newline("cp `dosbox -printconf` ~/" + std::string(e_name) + "/dosbox.conf");
        std::cout << newline << std::endl;
        system(newline.c_str());
        std::string yetnewline("cp -rf \"" + std::string(e_source_path) + "\" ~/" + std::string(e_name) + "/drive_c/");
        system(yetnewline.c_str());
        //
        // reate the basic run.conf
        std::string runconf_path(std::string(getenv("HOME")) + "/" + 
                std::string(e_name) + "/run.conf");
        std::cout << runconf_path << std::endl;
        std::ofstream runconf;
        runconf.open(runconf_path.c_str());
        runconf << "[autoexec]" << std::endl << "mount e ~/" << e_name << 
                "/drive_c/" << e_source_folder_name << std::endl << "e:" << std::endl << 
                e_exe_path << std::endl << "exit";
        runconf.close();

        // Create a new Entry from that and add it to the map
        std::pair<std::string, Entry > p = 
            make_pair(std::string(e_name), Entry(std::string(getenv("HOME"))+"/"+e_name));
        m_entries.insert(p);
    }
void ConfigFile::Load()
{
    std::ifstream   inFile( mFileName.c_str() );

    if( inFile.fail() )
    {
        inFile.close();
        throw FileNotFoundException( mFileName, Here );
    }

    String              sectionName;
    String              nextWord;
    char                buffer[512];
    std::stringstream   lineStream;
    
    inFile.getline(buffer, 512);
    while( inFile.good() )
    {        
        lineStream.clear();
        lineStream.str(buffer);
                
        // Read section name ("[Section Name]").
        lineStream >> sectionName;
        while( !lineStream.fail() )
        {
            lineStream >> nextWord;
            if( !lineStream.fail() )
            {
                sectionName += " ";
                sectionName += nextWord;
            }
        }        
        
        // Find opening and closing bracket (must be at start and end of section name).
        if( sectionName.at(0) != '[' || sectionName.at( sectionName.size() -1 ) != ']' )
        {
            inFile.close();
            throw InvalidConfigFileException( mFileName, Here );
        }

        // Extract the section name from the string (remove "[]")
        sectionName = sectionName.substr( 1, sectionName.length() - 2 );

        // Load this section.
        (*this)[sectionName].Load(inFile);

        // Read another section...
        inFile.getline(buffer, 512);
    }
}
void ConfigSection::Load( std::istream& pIn )
{
    String varName;
    String equalSign;
    String varValue;
    String nextWord;

    char              buffer[512];
    std::stringstream lineStream;

    while( pIn.good() )
    {
        varName    = "";
        equalSign  = "";
        varValue   = "";

        if( pIn.peek() == '[' )
            break;
        
        pIn.getline( buffer, 512 );

        lineStream.clear();
        lineStream.str(buffer);
                
        lineStream >> varName;
        lineStream >> equalSign;

        // Put the rest of the line in the value.
        lineStream >> varValue;
        while( !lineStream.fail() )
        {
            lineStream >> nextWord;
            if( !lineStream.fail() )
            {
                varValue += " ";
                varValue += nextWord;
            }
        }

        if( varName.empty() )
            continue;   // Line is empty.

        if( equalSign.empty() || varValue.empty() )
            throw InvalidConfigFileException( mConfigFile.GetFileName(), Here );

        // Create a new variable.
        (*this)[varName] = varValue;
    }
}
Exemple #4
0
void dosman::Entry::construct(void)
{
    DIR *dir;
    struct dirent *ent;
    int score;

    hasImage = false;
    hasConf = false;

    if ((dir = opendir (path.c_str())) != NULL) { 
        while ((ent = readdir (dir)) != NULL) {
            if (ent->d_name[0] == '.') continue;

            std::string filename(ent->d_name);
            std::string imagefile(DOSMAN_ENTRY_COVER);
            std::string dosboxconf(DOSMAN_ENTRY_CONF);

            if (filename.compare(0, imagefile.length(), imagefile) == 0) {
                hasImage = true;
                imagePath = path + "/" + filename;
                continue;
            }

            if (filename.compare(0, dosboxconf.length(), dosboxconf) == 0) {
                hasConf = true;
                continue;
            }
        }
        closedir (dir);

        if (!hasConf) throw InvalidEntryException(path);

        try {
            config = new KeyValueParser(path + "/" + DOSMAN_ENTRY_CONF);
        } catch (...) {
            throw InvalidConfigFileException(path);
        }
    }
}