/**
 * Function name			CInsertResource::ParseConfig
 * Description			
 * @return			void 
 * @exception			
 * @see			
*/
void CInsertResource::ParseConfig()
{
    //test if it's the config file. If not than the Handler was called from the main menu
    //and we have to construct the name of the config file
    CString SourceFile(m_sSourceFile); 
    if(GetExtentionFromFileName(SourceFile) != _T(".con"))
    {
        SAFEARRAY* parrFileNames;
	
        CComBSTR sClassType = _T("CONFIGURATION");
        HRESULT hRes = m_pICEProjectInfo->getClassesOfType(sClassType, &parrFileNames);
    
        BSTR HUGEP *pbstr;

        // Get a pointer to the elements of the array.
        hRes = ::SafeArrayAccessData(parrFileNames, (void HUGEP**)&pbstr);
        if (hRes==S_OK)
        {
            ASSERT((parrFileNames->rgsabound[0]).cElements>0);
            if ((parrFileNames->rgsabound[0]).cElements>0)
            {
                SourceFile = pbstr[0];
            }
        }

        ::SafeArrayUnaccessData(parrFileNames);
        ::SafeArrayDestroy(parrFileNames);
    }

    ReadFileContent(CString(m_ProjectPath) + _T("\\") + SourceFile, 
                    m_ConfigText);
    ASSERT(m_ConfigText.length() != 0);
    ASSERT(m_Config == NULL);
    parse_string(m_ConfigText, &m_Config);
}
/**
 * Function name			CDeleteObject::InformProjectManager
 * Description		invoke the project manager to delete the link associated
                    to this object from the 4cp file
 * @return			void 
 * @exception			
 * @see			    ICEProjInfo
*/
void CDeleteObject::InformProjectManager()
{
    HRESULT hRes = 0;
    ICEContainer *pICEContainer = NULL;
    BSTR sSF;
    hRes = m_pICEProjectInfo->getProjectName(&sSF);
    ASSERT(hRes==S_OK);
    CString SourceFile(sSF); 
    SysFreeString(sSF);

    CString StrId = SourceFile;
    SourceFile += _T(".4cp");
    sSF = SourceFile.AllocSysString();
    hRes = m_pICEProjectInfo->getContainerIFforFile(sSF, &pICEContainer);
   	ASSERT(hRes==S_OK);

    BSTR strFileName = m_sFileName.AllocSysString();
    hRes = pICEContainer->deleteLink(sSF,     
                                     m_sId, 
                                     strFileName);
    SysFreeString(strFileName);
    SysFreeString(sSF);
    ASSERT(hRes==S_OK);

    pICEContainer->Release();
}
/**
 * Function name			COperation::WriteFile
 * Description			
 * @param			CString sPouText
 * @return			void 
 * @exception			
 * @see			
*/
void CInsertResource::WriteFile(CString sPouText)
{
    try
    {
        //test if it's the config file. If not than the Handler was called from the main menu
        //and we have to construct the name of the config file
        CString SourceFile(m_sSourceFile); 
        if(GetExtentionFromFileName(SourceFile) != _T(".con"))
        {
            SAFEARRAY* parrFileNames;
	
            CComBSTR sClassType = _T("CONFIGURATION");
            HRESULT hRes = m_pICEProjectInfo->getClassesOfType(sClassType, &parrFileNames);

            BSTR HUGEP *pbstr;

            // Get a pointer to the elements of the array.
            hRes = ::SafeArrayAccessData(parrFileNames, (void HUGEP**)&pbstr);
            if (hRes==S_OK)
            {
                ASSERT((parrFileNames->rgsabound[0]).cElements>0);
                if ((parrFileNames->rgsabound[0]).cElements>0)
                {
                    SourceFile = pbstr[0];
                }
            }

            ::SafeArrayUnaccessData(parrFileNames);
            ::SafeArrayDestroy(parrFileNames);
        }
        //Create the res file
        CStdioFile File((CString)m_ProjectPath + _T("\\") + SourceFile,
                   CFile::modeWrite | CFile::modeCreate);
        File.Write(sPouText, sPouText.GetLength());
        File.Close();
        //Create the gvl file
        CString sImportFile = m_sName + _T(".gvl");
        CStdioFile GVLFile((CString)m_ProjectPath + _T("\\") + sImportFile,
                   CFile::modeWrite | CFile::modeCreate);
        
        CString StrHelp, Strlf = NEWLINE, StrOut = _T("");
        StrHelp.LoadString(IDS_KEY_COMMENT);
        StrOut += StrHelp;
        StrHelp.LoadString(IDS_GLOBVAR_FILE);
        StrOut += StrHelp;
        StrHelp.LoadString(IDS_KEY_ENDCOMMENT);
        StrOut += StrHelp;
        StrOut += Strlf;

        GVLFile.Write(StrOut, StrOut.GetLength());
        GVLFile.Close();
    }
    catch(CFileException* pFileException)
    {
        pFileException->ReportError();
        pFileException->Delete();
    }   
}
示例#4
0
bool AddDatastoreItemDialog::isSourceFileInInputDataset() const
{
  QString SourceFile(getSourceFilePath());

  if (SourceFile.isEmpty())
    return false;

  QString InputPath = QString::fromStdString(openfluid::base::RunContextManager::instance()->getInputDir());

  if (QDir::fromNativeSeparators(SourceFile).startsWith(QDir::fromNativeSeparators(InputPath)))
    return true;

  return false;
}
示例#5
0
void StateManager::CreateVertexShader(CONST DWORD* pFunction, HANDLE Shader)
{
    VShaderMap::iterator Iterator = VShaders.find(Shader);
    if(Iterator == VShaders.end())
    {
        VShader *NewShader = new VShader(pFunction, Shader);
        Assert(NewShader != NULL, "Out of memory in StateManager::CreateVertexShader");

        if(CaptureAllShaders && !VertexShaderSimulator.ContainsHash(NewShader->Hash()))
        {
            String AssemblyFilename = g_Context->Parameters.ShaderCaptureDirectory + String("VShader") + String::ZeroPad(String(NewShader->Hash()), 10) + ".txt";
            String SourceFilename   = g_Context->Parameters.ShaderCaptureDirectory + String("VShader") + String::ZeroPad(String(NewShader->Hash()), 10) + ".cpp";
            String HeaderFilename   = g_Context->Parameters.ShaderCaptureDirectory + String("VShader") + String::ZeroPad(String(NewShader->Hash()), 10) + ".h";
            ofstream AssemblyFile(AssemblyFilename.CString());
            NewShader->OutputDisassembly(AssemblyFile);
            if(g_Context->Parameters.OutputCSource)
            {
                ofstream SourceFile(SourceFilename.CString());
                ofstream HeaderFile(HeaderFilename.CString());
                NewShader->OutputCSource(SourceFile, HeaderFile);
            }
        }
        /*g_Context->Files.ShaderInfo << String::ZeroPad(String(NewShader->Hash()), 10) << '\t' << NewShader->Instructions.Length() << '\t';
        Vector<UINT> InstructionCounts;
        NewShader->ComputeShaderInstructionCounts(InstructionCounts);
        for(UINT InstructionIndex = 0; InstructionIndex < InstructionCounts.Length(); InstructionIndex++)
        {
            g_Context->Files.ShaderInfo << InstructionCounts[InstructionIndex];
            if(InstructionIndex != InstructionCounts.Length() - 1)
            {
                 g_Context->Files.ShaderInfo << '\t';
            }
        }
        g_Context->Files.ShaderInfo << endl;*/
        VShaders[Shader] = NewShader;
    }
    else
    {
        //g_Context->Files.Assert << "Double-create on same VShader handle\n";
    }
}
/**
 * Function name			CInsertResource::InformProjectManager
 * Description			
 * @return			void 
 * @exception			
 * @see			
*/
void CInsertResource::InformProjectManager()
{
    //Inform about the new resource
    //have to parse the config file
    CString ConFile = m_sSourceFile; 
    HRESULT hRes;
  
    if(GetExtentionFromFileName(ConFile) != _T(".con"))
    {
        SAFEARRAY* parrFileNames;
	
        CComBSTR sClassType = _T("CONFIGURATION");
        hRes = m_pICEProjectInfo->getClassesOfType(sClassType, &parrFileNames);
    
        BSTR HUGEP *pbstr;

        // Get a pointer to the elements of the array.
        hRes = ::SafeArrayAccessData(parrFileNames, (void HUGEP**)&pbstr);
        if (hRes==S_OK)
        {
            ASSERT((parrFileNames->rgsabound[0]).cElements>0);
            if ((parrFileNames->rgsabound[0]).cElements>0)
            {
                ConFile = pbstr[0];
            }
        }

        ::SafeArrayUnaccessData(parrFileNames);
        ::SafeArrayDestroy(parrFileNames);
    }

    if (!ConFile.IsEmpty())
    {
        BSTR strFileName = ConFile.AllocSysString();
        hRes = m_pICEProjectInfo->fileChangedHint(strFileName);
        ::SysFreeString(strFileName);
   	    ASSERT(hRes==S_OK);
    }

    //Inform about the new gvl file
    ICEContainer *pICEContainer = NULL;
    BSTR sSF;
    hRes = m_pICEProjectInfo->getProjectName(&sSF);
    ASSERT(hRes==S_OK);
    CString SourceFile(sSF); 
    SysFreeString(sSF);

    CString StrId = SourceFile;
    SourceFile += _T(".4cp");
    sSF = SourceFile.AllocSysString();
    hRes = m_pICEProjectInfo->getContainerIFforFile(sSF, &pICEContainer);
   	ASSERT(hRes==S_OK);
    CString sImportFile = m_sName + _T(".gvl");
    BSTR strGVLFileName = sImportFile.AllocSysString();
    
    //Contructing the Id needed by the Project Manager
    StrId = _T("/") + StrId + _T(".") + _T("CLASSVIEW") + _T("/") 
         + _T("Classes.GVLs");
    BSTR sId = StrId.AllocSysString();
    //Creating the link
    hRes = pICEContainer->createLink(sSF, sId, strGVLFileName);
    SysFreeString(strGVLFileName);
    SysFreeString(sId);
    SysFreeString(sSF);

    //ASSERT(hRes==S_OK);

    pICEContainer->Release();
}
示例#7
0
//! Added by Amir Krifa.
//! Used to load a Meta Info File, not in a network manner.
void MetainfoSocket::LoadMetaInfoFile(bool bSeeding,string MetaInfoFilePath)
{
	this->SetMetaInfoFileToLoad(MetaInfoFilePath);
	try
	{
		FILE *fil = fopen(m_filename.c_str(), "rb");
		m_fil=fil;
		if (fil)
		{
			PeerHandler& ref = static_cast<PeerHandler&>(Handler());
			BString meta;
			meta.read_file(fil,m_filename);
			fclose(fil);
			std::string info_hash = meta.GetHashAsString("info");
			// copy metainfo file
			std::string copy_to = ref.GetTorrentDirectory() + "\\" + info_hash + "\\.metainfo";
			
			ref.mkpath(copy_to);
			fil = fopen(m_filename.c_str(), "rb");
			if (fil)
			{
				FILE *fil2 = fopen(copy_to.c_str(), "wb");
				char buf[1000];
				size_t n = fread(buf, 1, 1000, fil);
				while (n > 0)
				{
					fwrite(buf, 1, n, fil2);
					n = fread(buf, 1, 1000, fil);
				}
				fclose(fil2);
				fclose(fil);
			}
			if (ref.SessionExists(info_hash))
			{
			}
			else
			{
				Session *sess = new Session(dynamic_cast<SocketHandler&>(Handler()), info_hash, bSeeding,string(ref.GetTorrentDirectory() + "\\" + info_hash + "\\" ));
				ref.RegSession( sess );
				sess -> SetHash(meta.GetHash("info"));
				
				BTString *p;
				if ((p = meta.GetString("announce")) != NULL)
				{
					sess -> SetAnnounce(p -> GetValue());
				}
				std::string name;
				if ((p = meta.GetString("info.name")) != NULL)
				{
					sess -> SetName(name = p -> GetValue());
				}
				BTInteger *piecelength = meta.GetInteger("info.piece length");
				if (piecelength)
				{
					sess -> SetPieceLength(piecelength -> GetVal());
				}
				BTInteger *length = meta.GetInteger("info.length");
				if (length)
				{
					sess -> AddFile(length -> GetVal());
				}
				else // info.files
				{
					BTObject *p = meta.GetBTObject("info.files");
					BTList *files = dynamic_cast<BTList *>(p);
					if (files)
					{
						btobject_v& ref = files -> GetList();
						for (btobject_v::iterator it = ref.begin(); it != ref.end(); it++)
						{
							BTDictionary *p = dynamic_cast<BTDictionary *>(*it);
							if (p)
							{
								BTInteger *length = dynamic_cast<BTInteger *>(p -> Find("length"));
								BTList *path = dynamic_cast<BTList *>(p -> Find("path"));
								if (path && length)
								{
									btobject_v& ref = path -> GetList();
									std::string pathname = name;
									for (btobject_v::iterator it = ref.begin(); it != ref.end(); it++)
									{
										BTString *p = dynamic_cast<BTString *>(*it);
										if (p)
											pathname += "\\" + p -> GetValue();
									}
									sess -> AddFile(pathname, length -> GetVal());
								}
								path=NULL;
								length=NULL;
							}
							p=NULL;
						}
					}
					files=NULL;
				}
				//! pieces checksum
				BTString *pieces = meta.GetString("info.pieces");
				if (pieces)
				{
					sess -> SetPieces( pieces -> GetValue() );
				}
				pieces =NULL;
				sess->SetFileToSeedPath(MetaInfoFilePath.substr(0,MetaInfoFilePath.find_last_of(".")));
				if(sess->isSeeding())
				{
					
					//! Copy the file to seed to the Torrents Directory
					string SourceFile(sess->GetFileToSeedPath());
					string DestFile(ref.GetTorrentDirectory() + "\\" + info_hash + "\\"+sess->GetName());
					if(CopyFile(ConvertLPCSTRToLPWSTR((char*)SourceFile.c_str()),ConvertLPCSTRToLPWSTR((char *)DestFile.c_str()),FALSE)==0)
					{
						
						//! Source File Not Found
						MessageBox( NULL,TEXT("Error encountred while trying to copy the file to seed."),
                            TEXT("Error while copying the source file."), MB_OK|MB_ICONSTOP );
               
					}
						
				}
				sess -> CreateFileManager();
				//! restore session
				sess -> Load();
				sess->Verify();
				sess=NULL;

			}
			
		}
	}
	catch (string)
	{
	}
	
}
示例#8
0
void GenerateEntitiesTable (const CString &sDataFile, CXMLElement *pCmdLine)
	{
	int i;
	ALERROR error;

	CString sSourceFile;
	if (!pCmdLine->FindAttribute(FILE_ATTRIB, &sSourceFile))
		{
		printf("Specify file\n");
		return;
		}

	//	Open the data file and parse all entities

	CSymbolTable Entities(FALSE, TRUE);
	CFileReadBlock DataFile(CONSTLIT("Transcendence.xml"));

	if (error = DataFile.Open())
		{
		printf("Unable to open Transcendence.xml\n");
		return;
		}

	char *pPos = DataFile.GetPointer(0, -1);
	char *pEnd = pPos + DataFile.GetLength();

	//	Look for "<!ENTITY"

	CString sName;
	DWORD dwValue;
	while (NextEntity(&pPos, pEnd, &sName, &dwValue))
		Entities.AddEntry(sName, (CObject *)dwValue);

	DataFile.Close();

	//	Open the source file and look for all entity references

	CFileReadBlock SourceFile(sSourceFile);
	if (error = SourceFile.Open())
		{
		printf("Unable to open %s\n", sSourceFile.GetASCIIZPointer());
		return;
		}

	pPos = SourceFile.GetPointer(0, -1);
	pEnd = pPos + SourceFile.GetLength();

	//	Look for entity references

	CSymbolTable Output(TRUE, TRUE);
	while (NextEntityReference(&pPos, pEnd, &sName))
		{
		//	Look for this entity

		DWORD dwValue;
		if (Entities.Lookup(sName, (CObject **)&dwValue) == NOERROR)
			{
			//	Start with the entity keyword

			CString sOutput = strPatternSubst(CONSTLIT("\t<!ENTITY %s"), sName);

			//	Add tabs

			int iTabs = (40 - (sOutput.GetLength() + 3) + 3) / 4;
			if (iTabs)
				sOutput.Append(strRepeat(CONSTLIT("\t"), iTabs));
			else
				sOutput.Append(CONSTLIT(" "));

			//	Add the value

			char szBuffer[1024];
			wsprintf(szBuffer, "\"0x%08X\">\n", dwValue);
			sOutput.Append(CString(szBuffer));

			//	Output to the table (in UNID order)

			Output.AddEntry(CString(szBuffer), new CString(sOutput));
			}
		}

	SourceFile.Close();

	//	Output table

	for (i = 0; i < Output.GetCount(); i++)
		{
		CString *pLine = (CString *)Output.GetValue(i);
		printf(pLine->GetASCIIZPointer());
		}
	}