/**
   This function will take the 'baseDir' and put the 'insideDir' after
   it so that it winds up with 'baseDir/insideDir/'.  It will take
   care of slashes, making sure there is one between them and one at
   the end, and the slashes will match what the operating system
   expects.

   @param dest the place to put the result
   @param destLength the length of the place to put the results
   @param baseDir the directory to start with
   @param insideDir the directory to place after the baseDir 
**/
AREXPORT void ArUtil::addDirectories(char *dest, size_t destLength, 
				     const char *baseDir,
				     const char *insideDir)
{
  // start it off
  strncpy(dest, baseDir, destLength - 1);
  // make sure we have a null term
  dest[destLength - 1] = '\0';
  // toss on that slash
  appendSlash(dest, destLength);
  // put on the inside dir
  strncat(dest, insideDir, destLength - strlen(dest) - 1);
  // now toss on that slash
  appendSlash(dest, destLength);
  // and now fix up all the slashes
  fixSlashes(dest, destLength);
}
bool CodaClientApplication::parseArgument(const QString &a, int argNumber, QString *errorMessage)
{
    switch (argNumber) {
    case 1:
        m_mode = modeArg(a);
        if (m_mode == Invalid) {
            *errorMessage = QLatin1String("Invalid mode");
            return false;
        }
        return true;
    case 2:  { // Address/port
        m_address = a;
        const int colonPos = m_address.indexOf(':');
        if (colonPos != -1) {
            m_port = m_address.mid(colonPos + 1).toUInt();
            m_address.truncate(colonPos);
        }
    }
        break;
    case 3:
        switch (m_mode) {
        case Launch:
            m_launchBinary = fixSlashes(a);
            break;
        case Install:
            m_installSisFile = a;
            break;
        case Uninstall:
            m_uninstallPackage = a.toUInt(0, 0);
            if (!m_uninstallPackage) {
                *errorMessage = QLatin1String("Invalid UID");
                return false;
            }
            break;
        case Put:
            m_putLocalFile = a;
            break;
        case Stat:
            m_statRemoteFile = fixSlashes(a);
            break;
        default:
            break;
        }
        return true;
    case 4:
        switch (m_mode) {
        case Launch:
            m_launchUID = a.toUInt(0, 0);
            if (!m_launchUID) {
                *errorMessage = QLatin1String("Invalid UID");
                return false;
            }
            break;
        case Install:
            m_installTargetDrive = a;
            break;
        case Put:
            m_putRemoteFile = fixSlashes(a);
            break;
        default:
            break;
        }
        return true;

    default:
        if (m_mode == Launch)
            m_launchArgs.push_back(a);
        break;
    }
    return true;
}
Exemplo n.º 3
0
Path::Path(const char* path)
	: _path(path)
{
	fixSlashes();
}
Exemplo n.º 4
0
Path::Path(const std::string& path)
	: _path(path)
{
	fixSlashes();
}
Exemplo n.º 5
0
Path::Path(const Path& rhs)
	: _path(rhs)
{
	fixSlashes();
}
Exemplo n.º 6
0
void CVirtualFS::setBaseDir(const string &basedir){
	mBaseDir = fixSlashes(basedir);
	if(mBaseDir[mBaseDir.size() - 1] == '/'){
		mBaseDir = mBaseDir.substr(0, mBaseDir.size() - 1);
	}
}
Exemplo n.º 7
0
void CFileCollection::readFile(CFile &file){
	unz_file_info info;
	U32 size;
	string name;
	switch(col_type){
	case NativeCollection:
		name = fixSlashes(file.getName());
		if(name[0] == '/')
			name.erase(name.begin());
		if (unzLocateFile(zh, name.c_str(), 2) == UNZ_OK){
			if (unzOpenCurrentFile(zh) == UNZ_OK){
				if (unzGetCurrentFileInfo(zh, &info, NULL, 0, NULL, 0, NULL, 0)!= UNZ_OK)
					return;
				size = info.uncompressed_size;
				file.setSize(size);
				if((U32)unzReadCurrentFile(zh, file.getData(), size) != size){
					unzCloseCurrentFile(zh);
					file.freeData();
					return;
				}
				unzCloseCurrentFile(zh);
				return;
			}
        } else {
            string fname = name + "/";
            if (unzLocateFile(zh, fname.c_str(), 2) == UNZ_OK){
                CVirtualFS::FindResult fr;
                Unz_GetStringForDir((unzFile*)zh, fname, "", fr);
                string data;
                CVirtualFS::FindResult::iterator i;
                for(i = fr.begin();i != fr.end();i++){
                    data += (*i).getName();
                    data += "\n";
                }
                data += "\0";
                file.setSize(data.size());
                memcpy(file.getData(), data.c_str(), data.size());
                file.setIsDirectory(true);
                return;
            }
        }
		break;
	case Directory:
		S32 i = 0;
		FILE *fp = 0;
		U32 size;

		string fullName = file.getName();
		i = fullName.find(mMountPoint, 0);
		if(i == string::npos){
			return;
		}
		fullName.replace(i, mMountPoint.size(), "");
		if(fullName[0] == '/')
			fullName.replace(0, 1, "");

		fullName = colPath + fullName;

#ifdef _WIN32
		struct	_finddata_t fileinfo;

		string pattern = fullName + "/*.*";

		S32 hd = _findfirst(pattern.c_str(), &fileinfo);
		if(hd != -1){
			// It is a directory
			string data("");
			do {
				data += fullName + "/" + fileinfo.name + "\n";
			} while (_findnext(hd, &fileinfo) != -1);
			data += "\0";
			file.setSize(data.size());
			memcpy(file.getData(), data.c_str(), data.size());
			file.setIsDirectory(true);
			_findclose(hd);
			return;
		}

#else
		//assert(0 && "NOT IMPLEMENTED DIRECTORY CHECK");
		DIR *dirp;
		struct dirent *dp;

		dirp = opendir(fullName.c_str());
		if(dirp){
			string data("");
			while( (dp = readdir(dirp)) != NULL ){
				if(*dp->d_name == '.')
					continue;
				data += fullName + "/" + dp->d_name + "\n";
			}
			data += "\0";
			file.setSize(data.size());
			memcpy(file.getData(), data.c_str(), data.size());
			file.setIsDirectory(true);
			closedir(dirp);
			return;
		}

#endif
#ifdef _WIN32
		while((i = fullName.find('/', i)) != string::npos){
			fullName.replace(i, 1, "\\");
		}
#endif

		if (!fp) fp = fopen(fullName.c_str(), "rb"); 
		if (fp) { 
			fseek(fp, 0, SEEK_END); 
			size = ftell(fp); 
			fseek(fp, 0, SEEK_SET);
			file.setSize(size);
			if (file.getData())
				fread(file.getData(), 1, size, fp); 
			fclose(fp);
			return;
		}
	}
}