#include <fthelper.h>
Static Public Member Functions | |
static CCLexFile * | ConvertFile (CCLexFile *pFile) |
Default constructor. | |
Static Protected Member Functions | |
static void | SetHResultError (HRESULT hr) |
Sets an error from a TemplMan error HRESULT. | |
static IFTManipulator * | CreateTemplMan (void) |
Creates a FlareTemplateManipulator object. |
Definition at line 117 of file fthelper.h.
|
Default constructor.
Definition at line 138 of file fthelper.cpp. 00139 { 00140 ERROR2IF(pFile == NULL, FALSE, "NULL file in FTHelper::ConvertFile"); 00141 00142 String_256 InputFile = pFile->GetPathName().GetPath(); 00143 00144 if (InputFile.IsEmpty()) 00145 return(NULL); 00146 00147 BSTR pInputName = T2BSTR((TCHAR*)InputFile); 00148 if (pInputName == NULL) 00149 { 00150 Error::SetError(_R(IDS_OUT_OF_MEMORY)); 00151 return(NULL); 00152 } 00153 00154 HRESULT hr = S_OK; 00155 CCDiskFile* pNewFile = NULL; 00156 00157 IFTManipulator* pTemplMan = CreateTemplMan(); 00158 if (pTemplMan != NULL) 00159 { 00160 // Initialise the manipulator object 00161 HRESULT hr = pTemplMan->Init(pInputName); 00162 if (SUCCEEDED(hr)) 00163 { 00164 PathName TempPath = FileUtil::GetTemporaryPathName(); 00165 String_256 OutFile = TempPath.GetPath(); 00166 if (!OutFile.IsEmpty()) 00167 { 00168 // Get file name as a BSTR 00169 BSTR pOutputName = T2BSTR((TCHAR*)OutFile); 00170 // And process it (will fail if NULL) 00171 hr = pTemplMan->ProcessTemplateToFile(pOutputName); 00172 if (SUCCEEDED(hr)) 00173 { 00174 // Create a default diskfile 00175 pNewFile = new CCDiskFile(); 00176 if (pNewFile != NULL) 00177 { 00178 if (!pNewFile->open(TempPath, ios::in | ios::binary)) 00179 { 00180 // If we failed then delete the file 00181 // and set the pointer to NULL for return 00182 delete pNewFile; 00183 pNewFile = NULL; 00184 } 00185 } 00186 } 00187 SysFreeString(pOutputName); 00188 } 00189 } 00190 // Release the interface 00191 pTemplMan->Release(); 00192 pTemplMan = NULL; 00193 } 00194 00195 if (FAILED(hr)) 00196 { 00197 SetHResultError(hr); // set the error 00198 ERROR3IF(pNewFile != NULL, "ConvertFile failed but created new file"); 00199 } 00200 00201 // Free the input BSTR 00202 SysFreeString(pInputName); 00203 00204 return(pNewFile); 00205 }
|
|
Creates a FlareTemplateManipulator object.
Definition at line 220 of file fthelper.cpp. 00221 { 00222 IFTManipulator* pTemplMan = NULL; 00223 00224 // Create an FTManipulator object 00225 HRESULT hr = CoCreateInstance(CLSID_FTManipulator, 00226 NULL, 00227 CLSCTX_INPROC_SERVER, 00228 IID_IFTManipulator, 00229 (void**)&pTemplMan); 00230 00231 if (SUCCEEDED(hr)) 00232 { 00233 return(pTemplMan); 00234 } 00235 else 00236 { 00237 SetHResultError(hr); 00238 return(NULL); 00239 } 00240 }
|
|
Sets an error from a TemplMan error HRESULT.
Definition at line 252 of file fthelper.cpp. 00253 { 00254 if (SUCCEEDED(hr)) 00255 return; 00256 00257 INT32 ErrorID = _R(IDS_TEMPLMAN_BAD_TEMPLATE); // Default error 00258 INT32 PostFixID = 0; 00259 00260 switch (hr) 00261 { 00262 case REGDB_E_CLASSNOTREG: 00263 ErrorID = _R(IDS_TEMPLMAN_NOT_INSTALLED); 00264 break; 00265 00266 case E_OUTOFMEMORY: 00267 ErrorID = _R(IDS_OUT_OF_MEMORY); 00268 break; 00269 00270 case E_BADTEMPLATE: 00271 break; 00272 00273 case E_BADRECORD: 00274 { 00275 PostFixID = _R(IDS_TEMPLMAN_BAD_RECORD); 00276 break; 00277 } 00278 case E_BADDATAITEM: 00279 { 00280 PostFixID = _R(IDS_TEMPLMAN_BAD_DATA_ITEM); 00281 break; 00282 } 00283 default: 00284 { 00285 Error::SetError(_R(IDS_NOT_A_FLARETEMPLATE_FILE)); 00286 return; 00287 } 00288 } 00289 00290 String_256 strError; 00291 00292 if (!strError.Load(ErrorID)) // Try to load the string 00293 { 00294 Error::SetError(ErrorID); // Just set the error if it fails 00295 return; 00296 } 00297 00298 if (PostFixID != 0) 00299 { 00300 String_256 strPostFix; 00301 if (!strPostFix.Load(PostFixID)) // Load the postfix string 00302 { 00303 Error::SetError(ErrorID); // Just set the error if it fails 00304 return; 00305 } 00306 strError += strPostFix; // and append it 00307 } 00308 00309 // And set the error 00310 Error::SetError(ErrorID, strError, 0); // Why doesn't the module param default to 0 00311 }
|