// 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; }
// Read a project from a file. AProject *AProject_CreateFromFile (geVFile *FS) { AProject *pProject = NULL; char Buffer[1024]; // any line longer than this is an error geBoolean NoErrors; assert (FS != NULL); // create empty project NoErrors = ((pProject = AProject_Create ("")) != NULL); // check file version information NoErrors = NoErrors && (AProject_CheckFileVersion (FS) != GE_FALSE); // Sections can be in any order while (NoErrors && (geVFile_EOF (FS) == GE_FALSE)) { int Section; // read a line ApjReadResult rslt = AProject_GetNonBlankLine (FS, Buffer, sizeof (Buffer)); switch (rslt) { case READ_ERROR : geErrorLog_AddString (GE_ERR_FILEIO_READ, "Loading project",NULL); NoErrors = GE_FALSE; break; case READ_EOF : break; case READ_SUCCESS : { // get the section name and process that section geBoolean FoundIt; const ApjSectionDispatchEntry *pEntry = NULL; // determine which section, and go read that. for (FoundIt = GE_FALSE, Section = 0; (FoundIt == GE_FALSE) && (Section < ApjNumSections); ++Section) { pEntry = &ApjSectionDispatchTable[Section]; FoundIt = (_strnicmp (Buffer, pEntry->SectionName, strlen (pEntry->SectionName)) == 0); } if (FoundIt) { NoErrors = pEntry->Load (pProject, FS); } else { // didn't find a good section name NoErrors = GE_FALSE; geErrorLog_AddString (GE_ERR_FILEIO_FORMAT, "Expected section name",NULL); } break; } } } if (!NoErrors) { // some kind of error occurred. // Clean up and exit if (pProject != NULL) { AProject_Destroy (&pProject); } } return pProject; }
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; }