Exemplo n.º 1
0
// Create empty project
AProject *AProject_Create (const char *OutputName)
{
	AProject *pProject;
	geBoolean NoErrors;
	char OutputNameAndExt[MAX_PATH];

	assert (OutputName != NULL);

	pProject = GE_RAM_ALLOCATE_STRUCT (AProject);
	if (pProject == NULL)
	{
		geErrorLog_AddString (GE_ERR_MEMORY_RESOURCE, "Allocating project structure",NULL);
		return NULL;
	}

	// Initialize defaults
	// Output
	pProject->Output.Filename = NULL;
	pProject->Output.Fmt = ApjOutput_Binary;

	// Paths
	pProject->Paths.ForceRelative = GE_TRUE;
	pProject->Paths.Materials = NULL;

	// Body
	pProject->Body.Filename = NULL;
	pProject->Body.Fmt = ApjBody_Max;

	// Materials
	pProject->Materials.Count = 0;
	pProject->Materials.Items = NULL;

	// Motions
	pProject->Motions.Count = 0;
	pProject->Motions.Items = NULL;

	FilePath_SetExt (OutputName, ".act", OutputNameAndExt);

	// Allocate required memory
	NoErrors = 
		((pProject->Output.Filename = Util_Strdup (OutputNameAndExt)) != NULL) &&
		((pProject->Paths.Materials = Util_Strdup ("")) != NULL) &&
		((pProject->Paths.TempFiles = Util_Strdup (".\\BldTemp")) != NULL) &&
		((pProject->Body.Filename	= Util_Strdup ("")) != NULL);
		
	// Build motion and material arrays.  Initially empty.
	NoErrors = NoErrors &&
		((pProject->Materials.Items = Array_Create (1, sizeof (ApjMaterialEntry))) != NULL);

	NoErrors = NoErrors &&
		((pProject->Motions.Items = Array_Create (1, sizeof (ApjMotionEntry))) != NULL);

	// if unsuccessful, destroy any allocated data
	if (!NoErrors)
	{
		geErrorLog_AddString (GE_ERR_MEMORY_RESOURCE, "Initializing project structure",NULL);
		if (pProject != NULL)
		{
			AProject_Destroy (&pProject);
		}
	}

	return pProject;
}
Exemplo n.º 2
0
BOOL CAStudioApp::InitInstance()
{
	Enable3dControlsStatic();	// Call this when linking to MFC statically

	AOptions *Options = NULL;	// options structure holds INI file options
	char IniFilePath[MAX_PATH] ;

	// Set up INI file path
	{
		char AppPath[MAX_PATH];
		
		::GetModuleFileName (NULL, AppPath, MAX_PATH);
		::FilePath_GetDriveAndDir (AppPath, AppPath);

		::FilePath_AppendName (AppPath, rcstring_Load (AfxGetInstanceHandle (), IDS_INIFILE_NAME), IniFilePath);

		// Set our INI file
		::free ((void *)m_pszProfileName);
		m_pszProfileName = ::_tcsdup (IniFilePath);

	}

	// Parse command line for filename
	CAStudioCommandLineInfo cmdInfo;
	ParseCommandLine (cmdInfo);

	AProject *pProject = NULL;

	// load program options
	Options = AOptions_CreateFromFile (IniFilePath);
	bool KeepGoing = true;

	if (Options == NULL)
	{
		// couldn't load options.  Man, we're REALLY out of memory...
		AfxMessageBox (IDS_OPTIONSERR);
		return FALSE;
	}

	char LoadProjectName[2*MAX_PATH] = "";

	// if filename specified on command line, then try to load it
	if ((cmdInfo.ErrFlag == false) && (cmdInfo.InputFile != ""))
	{
		char Ext[MAX_PATH];

		if (::ShortPathToLongPath (cmdInfo.InputFile, LoadProjectName) == false)
		{
			// ShortPathToLongPath failed for some reason.  Use short filename.
			strcpy (LoadProjectName, cmdInfo.InputFile);
		}

		// if no extension, then append .apj
		if (FilePath_GetExt (LoadProjectName, Ext) == GE_FALSE)
		{
			FilePath_SetExt (LoadProjectName, ".apj", LoadProjectName);
		}

		pProject = AProject_CreateFromFilename (LoadProjectName);
		if (pProject == NULL)
		{
			// If unable to load, then tell user and ask for Ok/Cancel
			// Ok will create new project and launch program.
			// Cancel will exit program.
			CString ErrMsg;

			AfxFormatString1 (ErrMsg, IDS_READERROR, LoadProjectName);
			if (AfxMessageBox (ErrMsg, MB_ICONEXCLAMATION | MB_OKCANCEL) == IDCANCEL)
			{
				KeepGoing = false;
			}
		}
	}

	if (KeepGoing)
	{
		CAStudioPropSheet dlg (NULL, &pProject, Options, LoadProjectName);

		m_pMainWnd = &dlg;
		dlg.DoModal ();

		// all done.  Save options.
		AOptions_WriteToFile (Options, IniFilePath);
	}

	// Cleanup

	// Destroy options structure
	if (Options != NULL)
	{
		AOptions_Destroy (&Options);
	}

	// Destroy project structure
	if (pProject != NULL)
	{
		AProject_Destroy (&pProject);
	}
		
	geRam_ReportAllocations();
	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}