Example #1
0
String MakeAbsolutePath(const String &path)
{
    if (path.IsEmpty())
    {
        return "";
    }
    // canonicalize_filename treats "." as "./." (file in working dir)
    String abs_path = path == "." ? "./" : path;
#if defined (WINDOWS_VERSION)
    // NOTE: cannot use long path names in the engine, because it does not have unicode strings support
    //
    //char long_path_buffer[MAX_PATH];
    //if (GetLongPathNameA(path, long_path_buffer, MAX_PATH) > 0)
    //{
    //    abs_path = long_path_buffer;
    //}
#elif defined (PSP_VERSION)
    // FIXME: Properly construct a full PSP path
    return path;
#endif
    char buf[512];
    canonicalize_filename(buf, abs_path, 512);
    abs_path = buf;
    FixupPath(abs_path);
    return abs_path;
}
Example #2
0
String  MakePathNoSlash(const String &path)
{
    String dir_path = path;
    FixupPath(dir_path);
    dir_path.TrimRight('/');
    return dir_path;
}
bool
AdvData::Open(const std::string &filename)
{
    const char *mName = "AdvData::Open: ";

    ReleaseData();

    // If the file is an ".inp" file then we may have more than 1 domain file.
    if(filename.size() >= 3 &&
       filename.substr(filename.size()-3, filename.size()) == "inp")
    {
        // Open the file.
        ifstream ifile(filename.c_str());
        if (ifile.fail())
        {
            return false;
        }

        // Process the .inp file
        char line[1024];
        ifile.getline(line, 1024);
        int nDomains = 0;
        int tmp[4];
        if(sscanf(line, "%d %d %d %d", &tmp[0], &tmp[1], &tmp[2], &tmp[3]) == 4)
        {
            // This is not a .inp file. Assume it is PATRAN and skip it.
            EXCEPTION1(InvalidDBTypeException, "This is not an Adventure \".inp\" file");
        }
        if(sscanf(line, "%d", &nDomains) != 1)
        {
            // This is not a .inp file
            EXCEPTION1(InvalidDBTypeException, "This is not an Adventure \".inp\" file");
        }

        domainRecords.reserve(nDomains);
        for(int i = 0; i < nDomains; ++i)
        {
            AdvDataSet domain;

            ifile.getline(line, 1024);
            domain.modelFile = FixupPath(filename, line);

            ifile.getline(line, 1024);
            domain.resultFile = FixupPath(filename, line);

            debug4 << "Domain " << i << endl;
            debug4 << "\tmodelFile=" << domain.modelFile << endl;
            debug4 << "\tresultFile=" << domain.resultFile << endl;

            domainRecords.push_back(domain);
        }
        ifile.close();
    }
    else
    {
        AdvDataSet domain;
        domain.modelFile = filename;
        domainRecords.push_back(domain);
    }

    // Now that we have a set of model and result files, open each of the
    // model files and determine how many subdomains are in them.
    int domainID = 0;
    for(size_t i = 0; i < domainRecords.size(); ++i)
    {
        AdvDocFile *f = adv_dio_file_open(domainRecords[i].modelFile.c_str(), "r");
        if(f == 0)
        {
            debug4 << mName << "Could not open " << domainRecords[i].modelFile
                   << " to determine its domain count." << endl;
            EXCEPTION1(InvalidDBTypeException, "Could not open Adventure file");
        }

        AdvDocument *doc = adv_dio_open_by_property(f, 0, "label", "HDDM_FEA_Model", 0);
        if(doc == 0)
        {
            debug4 << mName << "Could not get HDDM_FEA_Model" << endl;
            EXCEPTION1(InvalidDBTypeException, "Adventure file missing HDDM_FEA_Model");
        }

#ifdef TREAT_SUBDOMAINS_INDIVIDUALLY
        // We're not currently doing this but if we were, we'd need to change how 
        // we read data in AdvDataSet.
        int nSubDomains = 0;
        if(!adv_dio_get_property_int32(doc, "num_subdomains", &nSubDomains))
        {
            debug4 << mName << "Could not get num_subdomains" << endl;
            EXCEPTION1(InvalidDBTypeException, "Adventure file missing "
                "num_subdomains property");
        }

        for(int s = 0; s < nSubDomains; ++s)
        {
            domainToRecord[domainID] = i;
            domainRecords[i].SetDomainToSubDomain(domainID, s);
            domainID++;
        }
#else
        // Treat all subdomains as one domain
        domainToRecord[domainID] = i;
        domainRecords[i].SetDomainToSubDomain(domainID, 0);
        domainID++;
#endif
        adv_dio_close(doc);
        adv_dio_file_close(f);
    }

    // Read the file metadata.
    AdvDocFile *f = OpenFile(domainRecords[0].modelFile);
    if(f != 0)
    {
        ReadMetaDataFromFile(f, modelVars, elementType);

        f = OpenFile(domainRecords[0].resultFile);
        if(f != 0)
        {
            AdvDataSet::AdvElementType et;
            ReadMetaDataFromFile(f, resultVars, et);
        }
    }

    return true;
}
bool CCustom1Dlg::ComputeRelativePath( )
{
	if ( m_RootPath.GetAt(1) != ':' )
	{
		MessageBox( "Error! The root path must specify a drive!", "Bogus Root Path!", MB_ICONERROR | MB_OK );
		return false;
	}

	if ( m_TargetPath.GetAt(1) != ':' )
	{
		MessageBox( "Error! The target path must specify a drive!", "Bogus Target Path!", MB_ICONERROR | MB_OK );
		return false;
	}

	CString sourcePath;
	if (!Valvelibaw.m_Dictionary.Lookup("FULL_DIR_PATH", sourcePath ))
	{
		MessageBox( "I can't seem to find the source path!??!", "Umm... Get Brian", MB_ICONERROR | MB_OK );
		return false;
	}

	FixupPath( m_RootPath );
	FixupPath( m_TargetPath );
	FixupPath( sourcePath );

	CString srcRootPath = m_RootPath;
	srcRootPath += m_SrcPath;
	srcRootPath += "\\";
	FixupPath( srcRootPath );

	if (sourcePath.Find( srcRootPath ) != 0)
	{
		MessageBox( "Error! The source path must lie under the root source path!", "Bogus Root Path!", MB_ICONERROR | MB_OK );
		return false;
	}

	if (m_TargetPath.Find( m_RootPath ) != 0)
	{
		MessageBox( "Error! The target path must lie under the root path!", "Bogus Target Path!", MB_ICONERROR | MB_OK );
		return false;
	}

	int rootLen = m_RootPath.GetLength();
	int rootSrcLen = srcRootPath.GetLength();
	int sourceLen = sourcePath.GetLength();
	int targetLen = m_TargetPath.GetLength();
	CString relativePath = m_TargetPath.Right( targetLen - rootLen );

	// Now that we've got the relative source path, 
	// find out how many slashes are in it;
	// that'll tell us how many paths to back up....
	int i;
	CString relativeSourcePath = sourcePath.Right( sourceLen - rootLen );
	int numSlashes = CountSlashes(relativeSourcePath);
	CString targetRelativePath;
	for ( i = 0; i < numSlashes; ++i )
	{
		targetRelativePath += "..\\";
	}

	// Now that we've got the relative source path, 
	// find out how many slashes are in it;
	// that'll tell us how many paths to back up....
	CString rootSrcToProj = sourcePath.Right( sourceLen - rootSrcLen );
	numSlashes = CountSlashes(rootSrcToProj);
	CString projToRootSrc;
	for ( i = 0; i < numSlashes; ++i )
	{
		projToRootSrc += "..\\";
	}

	Valvelibaw.m_Dictionary["VALVE_ROOT_RELATIVE_PATH"] = targetRelativePath;
	Valvelibaw.m_Dictionary["VALVE_SRC_RELATIVE_PATH"] = projToRootSrc;
	targetRelativePath += relativePath;
	Valvelibaw.m_Dictionary["VALVE_ROOT_PATH"] = m_RootPath;
	Valvelibaw.m_Dictionary["VALVE_ROOT_SRC_PATH"] = srcRootPath;
	Valvelibaw.m_Dictionary["VALVE_TARGET_PATH"] = m_TargetPath;
	Valvelibaw.m_Dictionary["VALVE_RELATIVE_PATH"] = targetRelativePath;

	if (m_ToolProject)
		Valvelibaw.m_Dictionary["VALVE_TOOL"] = "1";
	if (m_PublicProject && (m_ProjectType != 2))
		Valvelibaw.m_Dictionary["VALVE_PUBLIC_PROJECT"] = "1";
	if (m_PublishImportLib && (m_ProjectType == 1))
		Valvelibaw.m_Dictionary["VALVE_PUBLISH_IMPORT_LIB"] = "1";

	// Import libraries
	if (m_ProjectType == 1)
	{
		if ( m_ImplibPath.GetAt(1) != ':' )
		{
			MessageBox( "Error! The import library path must specify a drive!", "Bogus Import Library Path!", MB_ICONERROR | MB_OK );
			return false;
		}

		if (m_ImplibPath.Find( srcRootPath ) != 0)
		{
			MessageBox( "Error! The import library path must lie under the root src path!", "Bogus Target Path!", MB_ICONERROR | MB_OK );
			return false;
		}

		int implibLen = m_ImplibPath.GetLength();
		relativePath = m_ImplibPath.Right( implibLen - rootSrcLen );
		int numSlashes = CountSlashes(rootSrcToProj);
		CString implibRelativePath;
		for (int i = 0; i < numSlashes; ++i )
		{
			implibRelativePath += "..\\";
		}
		implibRelativePath += relativePath;

		Valvelibaw.m_Dictionary["VALVE_IMPLIB_PATH"] = m_ImplibPath;
		Valvelibaw.m_Dictionary["VALVE_IMPLIB_RELATIVE_PATH"] = implibRelativePath;
	}

	return true;
}