/**
 * Creates the configuration file
 *
 * @param           
 * @return          
 * @exception       -
 * @see             
*/
HRESULT CProjectWizardData::CreateConfigurationFile ()
{
    HRESULT hr;
    FILE *pConfigurationFile;
    CString strFilename;
    int i;

    strFilename.Format (_T ("%s." FILE_EXT_CONFIGURATION), CONFIGURATION_FILE_NAME);

    hr = CreateFile (strFilename, &pConfigurationFile);
    if (hr != S_OK)
        return (hr);

    hr = AddSystemComment (pConfigurationFile);
    if (hr != S_OK)
    {
        fclose (pConfigurationFile);
        return (hr);
    };

    fprintf (pConfigurationFile, "CONFIGURATION %s\r\n", CONFIGURATION_FILE_NAME);

    for (i = 0; i < GetResourceCount (); ++i)
        fprintf (pConfigurationFile, "    #IMPORT \"%s." FILE_EXT_RESOURCE "\"\r\n", GetResource (i)->GetResource ());

    fprintf (pConfigurationFile, "END_CONFIGURATION\r\n");

    fclose (pConfigurationFile);

    return (S_OK);
}
/**
 * Checks whether the names entered by the user are correct identifiers
 *
 * @param           
 * @return          
 * @exception       -
 * @see             
*/
bool CProjectWizardData::CheckIdentifiers ()
{
    int iResource;

    for (iResource = 0; iResource < GetResourceCount (); ++iResource)
    {
        CProjectWizardResource *pResource;
        int iTask;

        pResource = GetResource (iResource);

        if (!CheckIdentifier (pResource->GetResource (), IDS_RESOURCE))
            return (false);

        if (!CheckIdentifier (pResource->GetTarget (), IDS_TARGET))
            return (false);

        for (iTask = 0; iTask < pResource->GetTaskCount (); ++iTask)
        {
            CProjectWizardTask *pTask;

            pTask = pResource->GetTask (iTask);

            if (!CheckIdentifier (pTask->GetName (), IDS_TASK))
                return (false);

            if (!CheckIdentifier (pTask->GetProgram (), IDS_PROGRAM))
                return (false);
        };
    };

    return (true);
}
VisParticleGroupDescriptor_cl *VisParticleGroupManager_cl::FindDescriptor(const char *szName) const
{
  const int iCount = GetResourceCount();
  for (int i=0;i<iCount;i++)
  {
    VisParticleEffectFile_cl *pFX = (VisParticleEffectFile_cl *)VisResourceManager_cl::GetResourceByIndex(i);
    if (!pFX) continue;
    VisParticleGroupDescriptor_cl *pDesc = pFX->FindDescriptor(szName);
    if (pDesc)
      return pDesc;
  }
  return NULL;
}
/**
 * Creates all files that depend on the resources
 *
 * @param           
 * @return          
 * @exception       -
 * @see             
*/
HRESULT CProjectWizardData::CreateResourceDependentFiles ()
{
    HRESULT hr;
    int i;

    for (i = 0; i < GetResourceCount (); ++i)
    {
        hr = CreateResourceDependentFiles (GetResource (i));
        if (hr != S_OK)
            return (hr);
    };

    return (S_OK);
}
/**
 * Creates the project file
 *
 * @param           
 * @return          
 * @exception       -
 * @see             
*/
HRESULT CProjectWizardData::CreateProjectFile()
{
    int i;
    HRESULT hrResult;
    FILE *pProjectFile;
    CString sFilename;


    // Create project file.
    //---------------------

    sFilename.Format (_T ("%s." FILE_EXT_PROJECT), m_strProjectName);

    hrResult = CreateFile (sFilename, &pProjectFile);
    if (hrResult != S_OK)
        return (hrResult);

    CString strProjectGuid;
    hrResult = CreateGuid(&strProjectGuid);


    // Write [Attributes] section (Alias, UserText1, UserText2, UserText3, UserURL)
    //-----------------------------------------------------------------------------------

    fprintf (pProjectFile, "[Attributes]\r\n");
    fprintf (pProjectFile, "GUID=\"%s\"\r\n", strProjectGuid);
    if (!m_strAlias.IsEmpty())
    {
        fprintf (pProjectFile, "Alias=%s\r\n", m_strAlias);
    }
    if (!m_strUserText1.IsEmpty())
    {
        fprintf (pProjectFile, "UserText1=%s\r\n", m_strUserText1);
    }
    if (!m_strUserText2.IsEmpty())
    {
        fprintf (pProjectFile, "UserText2=%s\r\n", m_strUserText2);
    }
    if (!m_strUserText3.IsEmpty())
    {
        fprintf (pProjectFile, "UserText3=%s\r\n", m_strUserText3);
    }
    if (!m_strURL.IsEmpty())
    {
        fprintf (pProjectFile, "UserURL=%s\r\n", m_strURL);
    }
    fprintf(pProjectFile, "\r\n");


    // Write [Format] section (version)
    //---------------------------------

    fprintf (pProjectFile, "[Format]\r\n");
    fprintf (pProjectFile, "version=V2.0\r\n\r\n");


    // Write [Classes.GVLs] section (.gvl file entries)
    //-------------------------------------------------

    fprintf (pProjectFile, "[Classes.GVLs]\r\n");

    for (i = 0; i < GetResourceCount (); ++i)
    {
        fprintf (pProjectFile, "file=%s." FILE_EXT_GLOBAL_VARIABLES "\r\n",
                 GetResource (i)->GetResource ());
    };

    fprintf(pProjectFile,"\r\n");


    // Write [Classes.Configurations] section (configuration .con file entries)
    //-----------------------------------------------------------

    fprintf (pProjectFile, "[Classes.Configurations]\r\n");
    fprintf (pProjectFile, "file=%s.con\r\n", CONFIGURATION_FILE_NAME);
    fprintf (pProjectFile, "\r\n");


    // Write [Classes.Constants] section (constant files)
    //---------------------------------------------------

    fprintf (pProjectFile, "[Classes.Constants]\r\n");

    for (i = 0; i < GetResourceCount (); ++i)
    {
        fprintf (pProjectFile, "file=%s." FILE_EXT_CONSTANTS "\r\n",
                 GetResource (i)->GetResource ());
    };

    fprintf (pProjectFile,"\r\n");


    // Write [Classes.Programs] section (program files)
    //-------------------------------------------------

    fprintf (pProjectFile, "[Classes.Programs]\r\n");

    for (i = 0; i < GetResourceCount (); ++i)
    {
        CProjectWizardResource *pResource;
        int k;

        pResource = GetResource (i);
        ASSERT (pResource != NULL);
        if (pResource== NULL)
            continue;

        for (k = 0; k < pResource->GetTaskCount (); ++k)
        {
            CProjectWizardTask *pTask;

            pTask = pResource->GetTask (k);
            ASSERT (pTask != NULL);
            if (pTask == NULL)
                continue;

            fprintf (pProjectFile, "file=%s\r\n", (LPCTSTR)BuildProgramFileName (pTask));
        };
    };

    fprintf (pProjectFile,"\r\n");


    // Write [Libs] section (library files)
    //-------------------------------------

    fprintf (pProjectFile, "[Libs]\r\n");

    for (i = 0; i < GetLibraryCount (); ++i)
        if (m_Libraries[i].GetSelectFlag ())
            fprintf (pProjectFile, "file=%s\\%s\r\n", _T("$(LIBDIR)"), m_Libraries[i].GetLibraryName ());

    fprintf (pProjectFile,"\r\n");


    // Write [Targets] section (target files)
    //---------------------------------------

    fprintf (pProjectFile,"[Targets]\r\n");

    for (i = 0; i < GetResourceCount (); ++i)
        fprintf (pProjectFile, "file=%s\r\n", BuildTargetFileName (GetResource (i)));

    fprintf (pProjectFile, "\r\n");


    fclose (pProjectFile);

    return (S_OK);
}
/**
 * Checks whether the names of resources, targets and programs are unique
 *
 * @param           
 * @return          
 * @exception       -
 * @see             
*/
bool CProjectWizardData::CheckUniqueNames ()
{
    int iResource1;
    int iResource2;
    int iTask1;
    int iTask2;
    CProjectWizardResource *pResource1;
    CProjectWizardResource *pResource2;
    CProjectWizardTask *pTask1;
    CProjectWizardTask *pTask2;
    int iNumResources = GetResourceCount();

    for (iResource1 = 0; iResource1 < iNumResources; ++iResource1)
    {
        pResource1 = GetResource(iResource1);

        for (iResource2 = iResource1 + 1; iResource2 < GetResourceCount (); ++iResource2)
        {
            pResource2 = GetResource (iResource2);

            if (!CompareNames (IDS_ERR_NON_UNIQUE_RESOURCE, pResource1->GetResource (), pResource2->GetResource (), TRUE))
                return (false);

            if (!CompareNames (IDS_ERR_NON_UNIQUE_TARGET, pResource1->GetTarget (), pResource2->GetTarget (), FALSE))
                return (false);
        };

        for (iTask1 = 0; iTask1 < pResource1->GetTaskCount (); ++iTask1)
        {
            pTask1 = pResource1->GetTask (iTask1);

            if (!CompareNames (IDS_ERR_EQUAL_TASK_AND_PROGRAM_NAME, pTask1->GetName (), pTask1->GetProgram (), TRUE))
                return (false);

            for (iTask2 = iTask1 + 1; iTask2 < pResource1->GetTaskCount (); ++iTask2)
            {
                pTask2 = pResource1->GetTask (iTask2);

                if (!CompareNames (IDS_ERR_NON_UNIQUE_TASK, pTask1->GetName (), pTask2->GetName (), TRUE))
                    return (false);

                if (!CompareNames (IDS_ERR_NON_UNIQUE_PROGRAM, pTask1->GetProgram (), pTask2->GetProgram (), TRUE))
                    return (false);

                if (!CompareNames (IDS_ERR_EQUAL_TASK_AND_PROGRAM_NAME, pTask1->GetName (), pTask2->GetProgram (), TRUE))
                    return (false);

                if (!CompareNames (IDS_ERR_EQUAL_TASK_AND_PROGRAM_NAME, pTask1->GetProgram (), pTask2->GetName (), TRUE))
                    return (false);
            };

            for (iResource2 = iResource1 + 1; iResource2 < GetResourceCount (); ++iResource2)
            {
                pResource2 = GetResource (iResource2);

                for (iTask2 = 0; iTask2 < pResource2->GetTaskCount (); ++iTask2)
                {
                    pTask2 = pResource2->GetTask (iTask2);

                    if (!CompareNames (IDS_ERR_NON_UNIQUE_PROGRAM, pTask1->GetProgram (), pTask2->GetProgram (), TRUE))
                        return (false);

                    if (!CompareNames (IDS_ERR_EQUAL_TASK_AND_PROGRAM_NAME, pTask1->GetName (), pTask2->GetProgram (), TRUE))
                        return (false);

                    if (!CompareNames (IDS_ERR_EQUAL_TASK_AND_PROGRAM_NAME, pTask1->GetProgram (), pTask2->GetName (), TRUE))
                        return (false);
                };
            };
        };
    };

    return (true);
}