Example #1
0
String FarPlugin::GetDLLPath()
{
    wchar_t buf[MAX_FILENAME];
    ::GetModuleFileName((HMODULE)hInstance, buf, _countof(buf));
    String dlln = buf;
    return dlln.substr(0, dlln.rfind('\\'));
}
Example #2
0
void Tag::setID( const String& newID )
{
    id = newID;
    size_t pos = newID.rfind( delimiter );
    if( pos == String::npos )
        shortID = newID;
    else
        shortID = newID.substr( pos+1, newID.length() - 1 );
}
Example #3
0
// FIXME method naming
String GetPerServerString(const String& orig, const ServerID& sid) {
    int32 dot_pos = orig.rfind(".");
    String prefix = orig.substr(0, dot_pos);
    String ext = orig.substr(dot_pos+1);

    char buffer[1024];
    sprintf(buffer, "%s-%04d.%s", prefix.c_str(), (uint32)sid, ext.c_str());

    return buffer;
}
Example #4
0
/**
GetFileName: Returns the base file name

@internalComponent
@released

@param aName - Input file name
@param aFile - Output parameter to hold the return value
*/
void Sis2Iby::GetFileName(String aName, String& aFile)
{
    TUint spos = 0, epos = 0;

    spos = aName.rfind(PATHSEPARATOR);
    if(spos != String::npos)
    {
        spos += 1;
    }
    else
    {
        spos = 0;
    }

    epos = aName.rfind(".");
    if(epos == String::npos)
    {
        epos = aName.size();
    }

    aFile.append(aName.substr(spos, (epos-spos)));
}
Example #5
0
String
ValueNode_Bone::unique_name(String name)const
{
	if (!find(name))
		return name;

	// printf("%s:%d making unique name for '%s'\n", __FILE__, __LINE__, name.c_str());

	size_t last_close(name.size()-1);
	int number = -1;
	String prefix;

	do
	{
		if (name.substr(last_close) != ")")
			break;

		size_t last_open(name.rfind('('));
		if (last_open == String::npos)
			break;

		if (last_open+2 > last_close)
			break;

		String between(name.substr(last_open+1, last_close - (last_open+1)));
		String::iterator iter;
		for (iter = between.begin(); iter != between.end(); iter++)
			if (!isdigit(*iter))
				break;

		if (iter != between.end())
			break;

		prefix = name.substr(0, last_open);
		number = atoi(between.c_str());
	} while (0);

	if (number == -1)
	{
		prefix = name + " ";
		number = 2;
	}

	do
	{
		name = prefix + "(" + strprintf("%d", number++) + ")";
	} while (find(name));

	// printf("%s:%d unique name is '%s'\n", __FILE__, __LINE__, name.c_str());
	return name;
}
Example #6
0
void Path::convertToCanonicalPath(String& path){
	//get real path
	//char buffer[FILENAME_MAX];
	//realpath(path,buffer);
	//path=buffer;
	//unix format:
	for(auto& c:path) if(c=='\\') c='/';
	//delete space at end
	int space_len=0;
	for(auto c:reverse(path))
		if(c==' ')
			++space_len;
		else
			break;
	path=path.substr(0,path.size()-space_len);
	//replace "void path"
	path.replace("//","");
	if(path.size()==0||path=="."||path=="./"){ path="./"; return; }
	//replace ../
	std::vector<String> dirs;
	path.split("/",dirs);
	path=""; //release
	for(uint i=0;i<dirs.size()-1;++i){
	 if(dirs[i]!="."){
		 if(dirs[i+1]!="..")
			path+=dirs[i]+"/";
		  else
			  ++i;
	 }
	}
	if(dirs.size()>1){
		 if(dirs[dirs.size()-1]!=".")
			 if(dirs[dirs.size()-1]!="..")
				path+=dirs[dirs.size()-1];
	}
	else
		path=dirs[0];
	//replace is made a void path..
	if(path.size()==0){ path="./"; return; }
	//directory?
	int point=path.rfind(".");
	int flash=path.rfind("/");
	//is a directory path
	if(flash>point){
		//if directory not have end part
		if(path[path.size()-1]!='/') path+='/';
	}
	//
}
const Vector<String> FileManagerWrapper::GetFileListByExtension(const String& path, const String& ext, int32 maxLevel)
{
    FileList fileList(path);

    Vector<String> list;
    for(int32 i = 0; i < fileList.GetCount(); ++i)
    {
        if(fileList.IsDirectory(i))
		{
			if (maxLevel > 0)
			{
				String subDirName = fileList.GetFilename(i) + "/";
				if (subDirName == "./" || subDirName == "../")
				{
					continue;
				}

				Vector<String> subDirList = GetFileListByExtension(path + subDirName, ext, maxLevel - 1);
				for (Vector<String>::iterator it = subDirList.begin(); it != subDirList.end(); ++it)
				{
					list.push_back(subDirName + *it);
				}
			}
			else
			{
				continue;
			}
		}

        String curFileName = fileList.GetFilename(i);
        int32 dotIndex = curFileName.rfind('.');
        if(dotIndex != String::npos)
        {
            String curFileExt = curFileName.substr(dotIndex);

            if(curFileExt == ext)
                list.push_back(curFileName);
        }
    }

    return list;
}
Example #8
0
  void
  UniqueIdInterface::setUniqueId(const String & rhs)
  {
    clearUniqueId();

    String::size_type last_underscore = rhs.rfind('_');
    String s = rhs.substr(last_underscore + 1);

    for (String::const_iterator s_i = s.begin(); s_i < s.end(); ++s_i)
    {
      int i = (*s_i - '0');
      if (i < 0 || i > 9)
      {
        clearUniqueId();
        return;
      }
      unique_id_ = 10 * unique_id_ + i;
    }

  }
Example #9
0
/**
AppendFileName: Appends file name to the given path

@internalComponent
@released

@param aPath - Source path
@param aFile - File name
*/
void Sis2Iby::AppendFileName(String& aPath, String aFile)
{
    TUint pos = 0;

    TrimQuotes(aPath);
    TrimQuotes(aFile);

    pos = aPath.rfind(PATHSEPARATOR);
    if(pos == String::npos)
    {
        aPath.append(PATHSEPARATOR);
    }

    if(pos < (aPath.length()-1))
    {
        aPath.append(PATHSEPARATOR);
    }

    GetFileName(aFile, aPath);
    return;
}
Example #10
0
/**
NormaliseSourceFile: Normalise the source file with its absolute path

@internalComponent
@released

@param aFile - Input file name
@param aPkgFile - Package file path
*/
void Sis2Iby::NormaliseSourceFile(String& aFile, String aPkgFile)
{
    String result;
    TUint pos = 0;

    pos = aPkgFile.rfind(PATHSEPARATOR);
    if(pos != String::npos)
    {
        result = aPkgFile.substr(0,pos);
    }
    else
    {
        result = ".";
    }

    result.append(PATHSEPARATOR);
    result.append(aFile);

    MakeFullPath(result);

    aFile = "\"" + result + "\"";
}
Example #11
0
void Sound::loadFile(String fileName) {

	if(soundLoaded) {
		alDeleteSources(1,&soundSource);	
	}

	String actualFilename = fileName;
	OSFILE *test = OSBasics::open(fileName, "rb");
	if(!test) {
		actualFilename = "default/default.wav";
	} else {
		OSBasics::close(test);	
	}
	
	String extension;
	size_t found;
	found=actualFilename.rfind(".");
	if (found!=string::npos) {
		extension = actualFilename.substr(found+1);
	} else {
		extension = "";
	}
	
	if(extension == "wav" || extension == "WAV") {
		buffer = loadWAV(actualFilename);			
	} else if(extension == "ogg" || extension == "OGG") {
		buffer = loadOGG(actualFilename);			
	}
	
	this->fileName = actualFilename;
	
	soundSource = GenSource(buffer);	
	
	reloadProperties();
	
	soundLoaded = true;
	
	checkALError("Sound load: complete");
}
Example #12
0
// Constructor: prefix number and filename, mainly for selfiles..
void FileName::compose(size_t no, const String &str)
{
    if (no == ALL_IMAGES || no == (size_t) -1)
        REPORT_ERROR(ERR_DEBUG_TEST, "Don't compose with 0 or -1 index, now images index start at 1");

    if (no != ALL_IMAGES)
    {
        size_t first = str.rfind(AT);
        if (first != npos)
        {
            std::vector<String> prefixes;
            int nPref = splitString(str.substr(0, first),",",prefixes, false);

            if (isalpha(prefixes[nPref-1].at(0)))
                formatStringFast(*this, "%06lu,%s", no, str.c_str());
        }
        else
            formatStringFast(*this, "%06lu@%s", no, str.c_str());
    }
    else
        *this = str;
}
    bool GLSupport::checkMinGLVersion(const String& v) const
    {
        unsigned int first, second, third;
        unsigned int cardFirst, cardSecond, cardThird;
        if(v == mVersion)
            return true;

        String::size_type pos = v.find(".");
        if(pos == String::npos)
            return false;

        String::size_type pos1 = v.rfind(".");
        if(pos1 == String::npos)
            return false;

        first = ::atoi(v.substr(0, pos).c_str());
        second = ::atoi(v.substr(pos + 1, pos1 - (pos + 1)).c_str());
        third = ::atoi(v.substr(pos1 + 1, v.length()).c_str());

        pos = mVersion.find(".");
        if(pos == String::npos)
            return false;

        pos1 = mVersion.rfind(".");
        if(pos1 == String::npos)
            return false;

        cardFirst  = ::atoi(mVersion.substr(0, pos).c_str());
        cardSecond = ::atoi(mVersion.substr(pos + 1, pos1 - (pos + 1)).c_str());
        cardThird  = ::atoi(mVersion.substr(pos1 + 1, mVersion.length()).c_str());

        if(first <= cardFirst && second <= cardSecond && third <= cardThird)
          return true;

        return false;
    }
Example #14
0
int main(int argc, char *argv[]) {
    Property p;
    p.fromCommand(argc,argv);

    // check where to put description of device
    ConstString dest = "";
    dest = p.check("doc",Value("")).toString();

    ConstString fileName = p.check("file",Value("default.ini")).asString();

    if (p.check("file")) {
        p.fromConfigFile(fileName);
    }

    ConstString deviceName = p.check("device",Value("")).asString();

    // if no device given, we should be operating a completely
    // standard test harness like for libYARP_OS and libYARP_sig
    if (deviceName=="") {
        return harness_main(argc,argv);
    }

    // device name given - use special device testing procedure

#ifdef CHECK_FOR_LEAKS
    mtrace();
#endif

    int result = 0;

    Network::init();
    Network::setLocalMode(true);

    String seek = fileName.c_str();
    ConstString exampleName = "";
    int pos = seek.rfind('/');
    if (pos==-1) {
        pos = seek.rfind('\\');
    }
    if (pos==-1) {
        pos = 0;
    } else {
        pos++;
    }
    int len = seek.find('.',pos);
    if (len==-1) {
        len = seek.length();
    } else {
        len -= pos;
    }
    exampleName = seek.substr(pos,len).c_str();
    ConstString shortFileName = seek.substr(pos,seek.length()).c_str();

    PolyDriver dd;
	YARP_DEBUG(Logger::get(), "harness opening...");
	
    bool ok = dd.open(p);
    YARP_DEBUG(Logger::get(), "harness opened.");
    result = ok?0:1;

    ConstString wrapperName = "";
    ConstString codeName = "";

    DriverCreator *creator = 
        Drivers::factory().find(deviceName.c_str());
    if (creator!=NULL) {
        wrapperName = creator->getWrapper();
        codeName = creator->getCode();
    }


    if (dest!="") {
        String dest2 = dest.c_str();
        if (result!=0) {
            dest2 += ".fail";
        }
        FILE *fout = fopen(dest2.c_str(),"w");
        if (fout==NULL) {
            printf("Problem writing to %s\n", dest2.c_str());
            exit(1);
        }
        fprintf(fout,"/**\n");
        fprintf(fout," * \\ingroup dev_examples\n");
        fprintf(fout," *\n");
        fprintf(fout," * \\defgroup %s Example for %s (%s)\n\n",
                exampleName.c_str(),
                deviceName.c_str(),
                exampleName.c_str());
        fprintf(fout, "Instantiates \\ref cmd_device_%s \"%s\" device implemented by %s.\n",
                deviceName.c_str(), deviceName.c_str(), codeName.c_str());
        fprintf(fout, "\\verbatim\n%s\\endverbatim\n",
                getFile(fileName.c_str()).c_str());
        fprintf(fout, "If this text is saved in a file called %s then the device can be created by doing:\n",
                shortFileName.c_str());
        fprintf(fout, "\\verbatim\nyarpdev --file %s\n\\endverbatim\n",
                shortFileName.c_str());
        fprintf(fout, "Of course, the configuration could be passed just as command line options, or as a yarp::os::Property object in a program:\n");
        fprintf(fout, "\\code\n");
        fprintf(fout, "Property p;\n");
        fprintf(fout, "p.fromConfigFile(\"%s\");\n",
                shortFileName.c_str());
        fprintf(fout, "// of course you could construct the Property object on-the-fly\n");
        fprintf(fout, "PolyDriver dev;\n");
        fprintf(fout, "dev.open(p);\n");
        fprintf(fout, "if (dev.isValid()) { /* use the device via view method */ }\n" );
        fprintf(fout, "\\endcode\n");
        fprintf(fout, "Here is a list of properties checked when starting up a device based on this configuration file.  Note that which properties are checked can depend on whether other properties are present.  In some cases properties can also vary between operating systems.  So this is just an example\n\n");
        toDox(dd,fout);
        fprintf(fout, "\n\\sa %s\n\n",
                codeName.c_str());
        fprintf(fout, " */\n");
        fclose(fout);
        fout = NULL;
    }

    if (ok) {
        YARP_DEBUG(Logger::get(), "harness closing...");
        dd.close();
        YARP_DEBUG(Logger::get(), "harness closed.");
    }

    // just checking for crashes, not device creation
    return result; //result;
}
    //-----------------------------------------------------------------------
    void FileSystemArchive::findFiles(const String& pattern, bool recursive, 
        bool dirs, StringVector* simpleList, FileInfoList* detailList) const
    {
        intptr_t lHandle, res;
        struct _finddata_t tagData;

        // pattern can contain a directory name, separate it from mask
        size_t pos1 = pattern.rfind ('/');
        size_t pos2 = pattern.rfind ('\\');
        if (pos1 == pattern.npos || ((pos2 != pattern.npos) && (pos1 < pos2)))
            pos1 = pos2;
        String directory;
        if (pos1 != pattern.npos)
            directory = pattern.substr (0, pos1 + 1);

        String full_pattern = concatenate_path(mName, pattern);

        lHandle = _findfirst(full_pattern.c_str(), &tagData);
        res = 0;
        while (lHandle != -1 && res != -1)
        {
            if ((dirs == ((tagData.attrib & _A_SUBDIR) != 0)) &&
				( !msIgnoreHidden || (tagData.attrib & _A_HIDDEN) == 0 ) &&
                (!dirs || !is_reserved_dir (tagData.name)))
            {
                if (simpleList)
                {
                    simpleList->push_back(directory + tagData.name);
                }
                else if (detailList)
                {
                    FileInfo fi;
                    fi.archive = this;
                    fi.filename = directory + tagData.name;
                    fi.basename = tagData.name;
                    fi.path = directory;
                    fi.compressedSize = tagData.size;
                    fi.uncompressedSize = tagData.size;
                    detailList->push_back(fi);
                }
            }
            res = _findnext( lHandle, &tagData );
        }
        // Close if we found any files
        if(lHandle != -1)
            _findclose(lHandle);

        // Now find directories
        if (recursive)
        {
            String base_dir = mName;
            if (!directory.empty ())
            {
                base_dir = concatenate_path(mName, directory);
                // Remove the last '/'
                base_dir.erase (base_dir.length () - 1);
            }
            base_dir.append ("/*");

            // Remove directory name from pattern
            String mask ("/");
            if (pos1 != pattern.npos)
                mask.append (pattern.substr (pos1 + 1));
            else
                mask.append (pattern);

            lHandle = _findfirst(base_dir.c_str (), &tagData);
            res = 0;
            while (lHandle != -1 && res != -1)
            {
                if ((tagData.attrib & _A_SUBDIR) &&
					( !msIgnoreHidden || (tagData.attrib & _A_HIDDEN) == 0 ) &&
                    !is_reserved_dir (tagData.name))
                {
                    // recurse
                    base_dir = directory;
                    base_dir.append (tagData.name).append (mask);
                    findFiles(base_dir, recursive, dirs, simpleList, detailList);
                }
                res = _findnext( lHandle, &tagData );
            }
            // Close if we found any files
            if(lHandle != -1)
                _findclose(lHandle);
        }
    }
Example #16
0
	//-----------------------------------------------------------------------
	String CgProgram::resolveCgIncludes(const String& inSource, Resource* resourceBeingLoaded, const String& fileName)
	{
		String outSource;
		// output will be at least this big
		outSource.reserve(inSource.length());

		size_t startMarker = 0;
		size_t i = inSource.find("#include");
		while (i != String::npos)
		{
			size_t includePos = i;
			size_t afterIncludePos = includePos + 8;
			size_t newLineBefore = inSource.rfind("\n", includePos);

			// check we're not in a comment
			size_t lineCommentIt = inSource.rfind("//", includePos);
			if (lineCommentIt != String::npos)
			{
				if (newLineBefore == String::npos || lineCommentIt > newLineBefore)
				{
					// commented
					i = inSource.find("#include", afterIncludePos);
					continue;
				}

			}
			size_t blockCommentIt = inSource.rfind("/*", includePos);
			if (blockCommentIt != String::npos)
			{
				size_t closeCommentIt = inSource.rfind("*/", includePos);
				if (closeCommentIt == String::npos || closeCommentIt < blockCommentIt)
				{
					// commented
					i = inSource.find("#include", afterIncludePos);
					continue;
				}

			}

			// find following newline (or EOF)
			size_t newLineAfter = inSource.find("\n", afterIncludePos);
			// find include file string container
			String endDelimeter = "\"";
			size_t startIt = inSource.find("\"", afterIncludePos);
			if (startIt == String::npos || startIt > newLineAfter)
			{
				// try <>
				startIt = inSource.find("<", afterIncludePos);
				if (startIt == String::npos || startIt > newLineAfter)
				{
					OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
						"Badly formed #include directive (expected \" or <) in file "
						+ fileName + ": " + inSource.substr(includePos, newLineAfter-includePos),
						"CgProgram::preprocessor");
				}
				else
				{
					endDelimeter = ">";
				}
			}
			size_t endIt = inSource.find(endDelimeter, startIt+1);
			if (endIt == String::npos || endIt <= startIt)
			{
				OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
					"Badly formed #include directive (expected " + endDelimeter + ") in file "
					+ fileName + ": " + inSource.substr(includePos, newLineAfter-includePos),
					"CgProgram::preprocessor");
			}

			// extract filename
			String filename(inSource.substr(startIt+1, endIt-startIt-1));

			// open included file
			DataStreamPtr resource = ResourceGroupManager::getSingleton().
				openResource(filename, resourceBeingLoaded->getGroup(), resourceBeingLoaded);

			// replace entire include directive line
			// copy up to just before include
			if (newLineBefore != String::npos && newLineBefore >= startMarker)
				outSource.append(inSource.substr(startMarker, newLineBefore-startMarker+1));

			size_t lineCount = 0;
			size_t lineCountPos = 0;
			
			// Count the line number of #include statement
			lineCountPos = outSource.find('\n');
			while(lineCountPos != String::npos)
			{
				lineCountPos = outSource.find('\n', lineCountPos+1);
				lineCount++;
			}

			// Add #line to the start of the included file to correct the line count
			outSource.append("#line 1 \"" + filename + "\"\n");

			outSource.append(resource->getAsString());

			// Add #line to the end of the included file to correct the line count
			outSource.append("\n#line " + Ogre::StringConverter::toString(lineCount) + 
				"\"" + fileName + "\"\n");

			startMarker = newLineAfter;

			if (startMarker != String::npos)
				i = inSource.find("#include", startMarker);
			else
				i = String::npos;

		}
		// copy any remaining characters
		outSource.append(inSource.substr(startMarker));

		return outSource;
	}
Example #17
0
String
SocketIMEngineGlobal::load_icon (const String &icon)
{
    String local_icon = icon;

    IconRepository::const_iterator it = m_icon_repository.find (icon);

    // The icon has been loaded, just return the local copy filename.
    if (it != m_icon_repository.end ())
        local_icon = it->second;

    // This icon is already available in local system, just return.
    if (scim_load_file (local_icon, 0) != 0)
        return local_icon;

    Transaction trans;
    int cmd;
    char *bufptr = 0;
    size_t filesize = 0;

    local_icon = String ("");

    init_transaction (trans);
    trans.put_command (SCIM_TRANS_CMD_LOAD_FILE);
    trans.put_data (icon);

    // Load icon file from remote SocketFrontEnd.
    if (send_transaction (trans) && receive_transaction (trans) &&
        trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY &&
        trans.get_data (&bufptr, filesize) &&
        trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_OK) {

        String tempfile;
        String::size_type pos = icon.rfind (SCIM_PATH_DELIM);

        if (pos != String::npos) {
            tempfile = icon.substr (pos + 1, String::npos);
        } else {
            tempfile = icon;
        }

        char tmp [80];
        snprintf (tmp, 80, "%lu", (unsigned long) m_socket_magic_key);

        tempfile = String (SCIM_TEMPDIR) + String (SCIM_PATH_DELIM_STRING) +
                   String ("scim-") + String (tmp) + String ("-") +
                   tempfile;

        SCIM_DEBUG_IMENGINE(1) << "Creating temporary icon file: " << tempfile << "\n";

        std::ofstream os (tempfile.c_str ());

        if (os) {
            os.write (bufptr, filesize);
            os.close ();

            // Check if the file is written correctly.
            if (scim_load_file (tempfile, 0) == filesize) {
                m_icon_repository [icon] = tempfile;
                local_icon = tempfile;
            } else {
                unlink (tempfile.c_str ());
            }
        }
    }

    delete [] bufptr;

    return local_icon;
}
Example #18
0
/** 
 * @brief Paint splashscreen.
 * Draws image to window size (which is already set to image size).
 * Then adds texts over image.
 */
void CSplashWnd::OnPaint()
{
	CPaintDC dc(this);
	m_pPicture->Render(&dc);

	CVersionInfo version(TRUE);
	CString s;
	CFont versionFont;
	CFont textFont;
	CFont copyrightFont;
	CFont *oldfont = NULL;

	int fontHeight = -MulDiv(VersionTextSize, dc.GetDeviceCaps(LOGPIXELSY), 72);
	BOOL fontSuccess = versionFont.CreateFont(fontHeight, 0, 0, 0, FW_BOLD, FALSE, FALSE,
		0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
		DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, FontName);
	if (fontSuccess)
		oldfont = dc.SelectObject(&versionFont);

	CString sVersion = version.GetFixedProductVersion().c_str();
	LangFormatString1(s, IDS_VERSION_FMT, sVersion);
	dc.SetBkMode(TRANSPARENT);
	
	RECT area = VersionTextArea;
	dc.DrawText(s, &area, VersionTextStyle);

	fontHeight = -MulDiv(DevelopersTextSize, dc.GetDeviceCaps(LOGPIXELSY), 72);
	fontSuccess = textFont.CreateFont(fontHeight, 0, 0, 0, 0, FALSE, FALSE,
		0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
		DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, FontName);
	if (fontSuccess)
	{
		// We already stored oldfont in previous font change
		if (oldfont == NULL)
			oldfont = dc.SelectObject(&textFont);
		else
			dc.SelectObject(&textFont);
	}

	String text = LoadResString(IDS_SPLASH_DEVELOPERS);

	// avoid dereference of empty strings and the NULL termiated character
	if (text.length() >= 0)
	{
		// Replace ", " with linefeed in developers list text to get
		// developers listed a name per line in the about dialog
		std::string::size_type pos = text.rfind(_T(", "));
		while (pos != std::string::npos)
		{
			text.replace(pos, 2, _T("\n"), 1);
			pos = text.rfind(_T(", "), pos - 1);
		}
	}

	area = DevelopersArea;
	dc.DrawText(text.c_str(), &area, DevelopersTextStyle);

	fontHeight = -MulDiv(CopyrightTextSize, dc.GetDeviceCaps(LOGPIXELSY), 72);
	fontSuccess = copyrightFont.CreateFont(fontHeight, 0, 0, 0, 0, FALSE, FALSE,
		0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
		DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, FontName);
	if (fontSuccess)
	{
		// We already stored oldfont in previous font change
		if (oldfont == NULL)
			oldfont = dc.SelectObject(&copyrightFont);
		else
			dc.SelectObject(&copyrightFont);
	}

	text = LoadResString(IDS_SPLASH_GPLTEXT);
	area = CopyrightArea;
	dc.DrawText(text.c_str(), &area, CopyrightTextStyle);

	if (oldfont != NULL)
		dc.SelectObject(oldfont);
}
Example #19
0
void Actor::LoadSpriteFrames(const String& firstFilename, GLint clampmode, GLint filtermode)
{
	int extensionLocation = firstFilename.rfind(".");
	int numberSeparator = firstFilename.rfind("_");
	int numDigits = extensionLocation - numberSeparator - 1;

	// Clear out the number of frames we think we have.
	_spriteNumFrames = 0;

	bool bValidNumber = true;
	// So you're saying I've got a chance?
	if (numberSeparator > 0 && numDigits > 0)
	{
		// Now see if all of the digits between _ and . are numbers (i.e. test_001.jpg).
		for (int i=1; i<=numDigits; ++i)
		{
			char digit = firstFilename[numberSeparator+i];
			if (digit < '0' || digit > '9')
			{
				bValidNumber = false;
				break;
			}
		}
	}

	// If these aren't valid, the format is incorrect.
	if (numberSeparator == (int)String::npos || numDigits <= 0 || !bValidNumber)
	{
		sysLog.Log("LoadSpriteFrames() - Bad Format - Expecting somename_###.ext");
		sysLog.Log("Attempting to load single texture: " + firstFilename);

		if (!SetSprite(firstFilename, 0, clampmode, filtermode))
			return;
	}

	// If we got this far, the filename format is correct.
	String numberString;
	// The number string is just the digits between the '_' and the file extension (i.e. 001).
	numberString.append(firstFilename.c_str(), numberSeparator+1, numDigits);

	// Get our starting numberical value.
	int number = atoi(numberString.c_str());

	String baseFilename;
	// The base name is everything up to the '_' before the number (i.e. somefile_).
	baseFilename.append( firstFilename.c_str(), numberSeparator+1);

	String extension;
	// The extension is everything after the number (i.e. .jpg).
	extension.append(firstFilename.c_str(), extensionLocation, firstFilename.length() - extensionLocation);

	// Keep loading until we stop finding images in the sequence.
	while (true)
	{
		// Build up the filename of the current image in the sequence.
		String newFilename = baseFilename + numberString + extension;
		
		// Were we able to load the file for this sprite?
		if (!SetSprite(newFilename, _spriteNumFrames, clampmode, filtermode, true /*optional*/))
		{
			break;
		}

		// Verify we don't go out of range on our hard-coded frame limit per sprite.
		if (_spriteNumFrames >= MAX_SPRITE_FRAMES)
		{
			sysLog.Log("Maximum number of frames reached (" + IntToString(MAX_SPRITE_FRAMES) + "). Bailing out...");
			sysLog.Log("Increment MAX_SPRITE_FRAMES if you need more.");
			break;
		}

		// Bump the number to the next value in the sequence.
		++number;

		// Serialize the numerical value to it so we can retrieve the string equivalent.
		std::stringstream sstr;
		sstr << number;
		String newNumberString = sstr.str();

		// We assume that all the files have as many numerical digits as the first one (or greater) (i.e. 01..999).
		// See if we need to pad with leading zeros.
		int numLeadingZeros = numDigits - (int)newNumberString.length();

		// Do the leading zero padding.
		for (int i=0; i<numLeadingZeros; ++i)
		{
			newNumberString = '0' + newNumberString;
		}

		// Save off the newly formulated number string for the next image in the sequence.
		numberString = newNumberString;
	}
}
Example #20
0
File *FileRef::create(FileName fileName, bool readAudioProperties,
                      AudioProperties::ReadStyle audioPropertiesStyle) // static
{

  List<const FileTypeResolver *>::ConstIterator it = FileRefPrivate::fileTypeResolvers.begin();

  for(; it != FileRefPrivate::fileTypeResolvers.end(); ++it) {
    File *file = (*it)->createFile(fileName, readAudioProperties, audioPropertiesStyle);
    if(file)
      return file;
  }

  // Ok, this is really dumb for now, but it works for testing.

  String ext;
  {
#ifdef _WIN32

    String s = fileName.toString();

#else

    String s = fileName;

 #endif

    const int pos = s.rfind(".");
    if(pos != -1)
      ext = s.substr(pos + 1).upper();
  }

  // If this list is updated, the method defaultFileExtensions() should also be
  // updated.  However at some point that list should be created at the same time
  // that a default file type resolver is created.

  if(!ext.isEmpty()) {
    if(ext == "MP3")
      return new MPEG::File(fileName, readAudioProperties, audioPropertiesStyle);
    if(ext == "OGG")
      return new Ogg::Vorbis::File(fileName, readAudioProperties, audioPropertiesStyle);
    if(ext == "OGA") {
      /* .oga can be any audio in the Ogg container. First try FLAC, then Vorbis. */
      File *file = new Ogg::FLAC::File(fileName, readAudioProperties, audioPropertiesStyle);
      if (file->isValid())
        return file;
      delete file;
      return new Ogg::Vorbis::File(fileName, readAudioProperties, audioPropertiesStyle);
    }
    if(ext == "FLAC")
      return new FLAC::File(fileName, readAudioProperties, audioPropertiesStyle);
    if(ext == "MPC")
      return new MPC::File(fileName, readAudioProperties, audioPropertiesStyle);
    if(ext == "WV")
      return new WavPack::File(fileName, readAudioProperties, audioPropertiesStyle);
    if(ext == "SPX")
      return new Ogg::Speex::File(fileName, readAudioProperties, audioPropertiesStyle);
    if(ext == "OPUS")
      return new Ogg::Opus::File(fileName, readAudioProperties, audioPropertiesStyle);
    if(ext == "TTA")
      return new TrueAudio::File(fileName, readAudioProperties, audioPropertiesStyle);
    if(ext == "M4A" || ext == "M4R" || ext == "M4B" || ext == "M4P" || ext == "MP4" || ext == "3G2")
      return new MP4::File(fileName, readAudioProperties, audioPropertiesStyle);
    if(ext == "WMA" || ext == "ASF")
      return new ASF::File(fileName, readAudioProperties, audioPropertiesStyle);
    if(ext == "AIF" || ext == "AIFF")
      return new RIFF::AIFF::File(fileName, readAudioProperties, audioPropertiesStyle);
    if(ext == "WAV")
      return new RIFF::WAV::File(fileName, readAudioProperties, audioPropertiesStyle);
    if(ext == "APE")
      return new APE::File(fileName, readAudioProperties, audioPropertiesStyle);
    // module, nst and wow are possible but uncommon extensions
    if(ext == "MOD" || ext == "MODULE" || ext == "NST" || ext == "WOW")
      return new Mod::File(fileName, readAudioProperties, audioPropertiesStyle);
    if(ext == "S3M")
      return new S3M::File(fileName, readAudioProperties, audioPropertiesStyle);
    if(ext == "IT")
      return new IT::File(fileName, readAudioProperties, audioPropertiesStyle);
    if(ext == "XM")
      return new XM::File(fileName, readAudioProperties, audioPropertiesStyle);
  }

  return 0;
}