#include <gtk/gtk.h>#include <gdk-pixbuf/gdk-pixbuf.h>#include <strings.h>#include <libermanifest/ermanifest.h>#include "FileManager.h"#include "FileMgr_page.h"#include "FileMgr_xml.h"#include "ScribbleDefine.h"#include "ScribbleLog.h"#include "ScribbleUtils.h"Go to the source code of this file.
Functions | |
| static int | get_result_dirname (char *sResultDir, int iSize, const char *sDataDir) |
| int | createDirHirachy (PFileManager pFM) |
| void | dumpFileManager (PFileManager pFM) |
| int | initFileManagerByTmpl (PFileManager pFM, const char *sTmplPathName) |
| int | initFileManagerByManifest (PFileManager pFM, const char *sManifestPathName) |
| void | FreeFileManager (PFileManager pFM) |
| char * | getAbsPathFromCurrScrib (char *sAbsFileName, int iSize, const char *currFileName, const PFileManager pFM) |
| int | get_ink_filename (char *inkFileName, int iSize, const PFileManager pFM) |
| int | get_result_filename (char *resultFileName, int iSize, const PFileManager pFM, const PScribPage pScribPage) |
| int | get_curr_result_filename (char *resultFileName, int iSize, const PFileManager pFM) |
| void | dumpManifest (Manifest *pM) |
| int createDirHirachy | ( | PFileManager | pFM | ) |
Definition at line 54 of file FileManager.c.
00055 { 00056 //if dir not exist, creat dirstruct 00057 const char* sDataDir=pFM->sDataDir; 00058 if( pFM->bNeedCreatDirHirachy && !FileExist(sDataDir) ) 00059 { 00060 SB_FMPRINTF("create for\n%s\n",sDataDir); 00061 if( 0!=CreateDir(sDataDir)) 00062 { 00063 SB_ERRORPRINTF("create directory [%s]fail\n",sDataDir); 00064 return -1; 00065 } 00066 SB_FMPRINTF("create directory [%s] ok\n",sDataDir); 00067 char sResultDir[MAX_PATHNAME+1]; 00068 //crearete ./result directory 00069 get_result_dirname(sResultDir,sizeof(sResultDir),sDataDir); 00070 if( 0!=CreateDir(sResultDir)) 00071 { 00072 SB_ERRORPRINTF("create directory [%s]fail\n",sResultDir); 00073 return -1; 00074 } 00075 SB_FMPRINTF("create directory [%s] ok\n",sResultDir); 00076 00077 //now we can init the handle to .irx inkfile. 00078 if( 0!=fm_initIrxHandle(pFM,FALSE) ) 00079 { 00080 SB_ERRORPRINTF("create .irx inkfile error\n"); 00081 return -1; 00082 } 00083 pFM->bNeedCreatDirHirachy=FALSE; 00084 SB_FMPRINTF("done\n"); 00085 } 00086 00087 return 0; 00088 }

| void dumpFileManager | ( | PFileManager | pFM | ) |
Definition at line 91 of file FileManager.c.
00092 { 00093 00094 SB_FMPRINTF("\n==========================================\n" 00095 "sTmplPathName=[%s]\n" 00096 "sManifestPathName=[%s]\n" 00097 "sDataDir=[%s]\n" 00098 "sScribbleName=[%s]\n" 00099 "========================================\n", 00100 pFM->sTmplPathName, 00101 pFM->sManifestPathName, 00102 pFM->sDataDir, 00103 pFM->manifest.sScribbleName); 00104 }
| void dumpManifest | ( | Manifest * | pM | ) |
Definition at line 298 of file FileManager.c.
00299 { 00300 printf("\n=================================\n" 00301 "sScribbleName=[%s]\n" 00302 "iLastOpenPage=[%d]\n" 00303 "iTotalPages=[%d]\n", 00304 pM->sScribbleName,pM->iLastOpenPage,pM->iTotalPages); 00305 PScribPage pPage=pM->pFirstScribPage;; 00306 while(pPage) 00307 { 00308 printf("----------------------------------\n"); 00309 printf("sImgFileName=[%s]\nsPageName=[%s]\n", 00310 pPage->sImgFileName,pPage->sPageName); 00311 printf("sImgFileName=[%s]\nsPageName=[%s]\nbDirty=%d\n", 00312 pPage->sImgFileName,pPage->sPageName,pPage->bDirty); 00313 00314 pPage=pPage->pNextPage; 00315 } 00316 printf("=================================\n"); 00317 }
| void FreeFileManager | ( | PFileManager | pFM | ) |
Definition at line 205 of file FileManager.c.
00206 { 00207 if( NULL==pFM ) return; 00208 00209 PScribPage pCurrPage=pFM->manifest.pFirstScribPage; 00210 PScribPage pNextPage=NULL; 00211 while(pCurrPage) 00212 { 00213 pNextPage=pCurrPage->pNextPage; 00214 //free scribpage inlcude ink object 00215 freeScribPage(pCurrPage); 00216 pCurrPage=pNextPage; 00217 } 00218 if( NULL!=pFM->irxHandle) 00219 { 00220 free(pFM->irxHandle); 00221 pFM->irxHandle=NULL; 00222 } 00223 memset(pFM,0,sizeof(FileManager)); 00224 }

| int get_curr_result_filename | ( | char * | resultFileName, | |
| int | iSize, | |||
| const PFileManager | pFM | |||
| ) |
Definition at line 291 of file FileManager.c.
00292 { 00293 return get_result_filename(resultFileName,iSize, 00294 pFM,getCurrScribPage(pFM)); 00295 }

| int get_ink_filename | ( | char * | inkFileName, | |
| int | iSize, | |||
| const PFileManager | pFM | |||
| ) |
Definition at line 250 of file FileManager.c.
00252 { 00253 //SB_FMPRINTF("__start__\n"); 00254 memset(inkFileName,0,iSize); 00255 snprintf( inkFileName,iSize-1, 00256 "%s%s.irx", 00257 pFM->sDataDir, 00258 pFM->manifest.sScribbleName); 00259 //SB_FMPRINTF("__end__\ninkFileName=%s\n", inkFileName); 00260 return 0; 00261 }
| static int get_result_dirname | ( | char * | sResultDir, | |
| int | iSize, | |||
| const char * | sDataDir | |||
| ) | [static] |
Copyright (C) 2005-2008 iRex Technologies B.V. All rights reserved.
Definition at line 265 of file FileManager.c.
00266 { 00267 SB_FMPRINTF("__start__\n"); 00268 memset(sResultDir,0,iSize); 00269 snprintf(sResultDir,iSize-1, "%sresult",sDataDir); 00270 SB_FMPRINTF("__end__\nresultdir=%s\n", sResultDir); 00271 return 0; 00272 }
| int get_result_filename | ( | char * | resultFileName, | |
| int | iSize, | |||
| const PFileManager | pFM, | |||
| const PScribPage | pScribPage | |||
| ) |
Definition at line 275 of file FileManager.c.
00277 { 00278 //SB_FMPRINTF("__start__\n"); 00279 if( NULL==pScribPage) return -1; 00280 00281 memset(resultFileName,0,iSize); 00282 snprintf( resultFileName,iSize-1, 00283 "%sresult/%s.png", 00284 pFM->sDataDir, 00285 pScribPage->sPageName); 00286 //SB_FMPRINTF("__end__\nresultfile=%s\n", resultFileName); 00287 return 0; 00288 }
| char* getAbsPathFromCurrScrib | ( | char * | sAbsFileName, | |
| int | iSize, | |||
| const char * | currFileName, | |||
| const PFileManager | pFM | |||
| ) |
Definition at line 228 of file FileManager.c.
00232 { 00233 memset(sAbsFileName,0,iSize); 00234 if( currFileName[0] == '/' ) 00235 { 00236 strncpy(sAbsFileName,currFileName,iSize-1); 00237 } 00238 else 00239 { 00240 00241 snprintf( sAbsFileName,iSize-1, 00242 "%s%s", 00243 pFM->sDataDir, 00244 currFileName); 00245 } 00246 return sAbsFileName; 00247 }
| int initFileManagerByManifest | ( | PFileManager | pFM, | |
| const char * | sManifestPathName | |||
| ) |
Definition at line 148 of file FileManager.c.
00149 { 00150 SB_FMPRINTF("init by \n%s\n",sManifestPathName); 00151 memset(pFM,0,sizeof(FileManager)); 00152 strncpy(pFM->sManifestPathName,sManifestPathName, 00153 sizeof(pFM->sManifestPathName)-1 ); 00154 if( 0!=loadManifest(pFM) ) 00155 { 00156 SB_ERRORPRINTF("load manifest[%s] error\n",sManifestPathName); 00157 return -1; 00158 } 00159 00160 GetDirFromFullName(pFM->sDataDir,sizeof(pFM->sDataDir),sManifestPathName); 00161 00162 pFM->isCreatedFromTmpl=FALSE; 00163 00164 SB_FMPRINTF("notes type is:[%s]",pFM->manifest.sInkType); 00165 //if type is not irex(current type), we need conversion it to new format 00166 if( 0!=strcasecmp(pFM->manifest.sInkType,SCRIB_TYPE) ) 00167 { 00168 SB_FMPRINTF("init by \n%s\n",sManifestPathName); 00169 if( 0!=fc_convertold2irx(pFM) ) 00170 { 00171 SB_ERRORPRINTF("converting error\n"); 00172 return -1; 00173 } 00174 pFM->bNeedSaveManifest=TRUE; 00175 SB_FMPRINTF("update manifest..."); 00176 strncpy(pFM->manifest.sInkType,SCRIB_TYPE,sizeof(pFM->manifest.sInkType)); 00177 //change the type to irx and save the manifest 00178 if( 0!=fm_setIrxTypeAndSave(pFM) ) 00179 { 00180 SB_ERRORPRINTF("save type error[%s]\n",pFM->sManifestPathName); 00181 return -1; 00182 } 00183 } 00184 00185 if( 0!=fm_initIrxHandle(pFM,TRUE) ) 00186 { 00187 SB_ERRORPRINTF("open .irx inkfile error\n"); 00188 return -1; 00189 } 00190 00191 pFM->bNeedSaveManifest=FALSE; 00192 00193 PScribPage pScribPage=jumptoScribPage(pFM,pFM->manifest.iLastOpenPage); 00194 if( NULL==pScribPage ) //no page 00195 return -1; 00196 //get template from CurrentPage 00197 strcpy(pFM->sTmplPathName,pScribPage->sImgFileName); 00198 00199 pFM->bNeedCreatDirHirachy=FALSE; 00200 00201 dumpFileManager(pFM); 00202 return 0; 00203 }

| int initFileManagerByTmpl | ( | PFileManager | pFM, | |
| const char * | sTmplPathName | |||
| ) |
Definition at line 107 of file FileManager.c.
00108 { 00109 SB_FMPRINTF("init by %s\n",sTmplPathName); 00110 int iLenOfSuffix=strlen(".bmp"); 00111 if( NULL==sTmplPathName || strlen(sTmplPathName)<=iLenOfSuffix ) 00112 return -1; 00113 00114 memset(pFM,0,sizeof(FileManager)); 00115 00116 strncpy(pFM->sTmplPathName,sTmplPathName, 00117 sizeof(pFM->sTmplPathName)-1); 00118 00119 GetDirFromFullName(pFM->sDataDir,sizeof(pFM->sDataDir),sTmplPathName); 00120 00121 if( 0!=getUniqNameForSCRIB(pFM) ) 00122 { 00123 return -1; 00124 } 00125 //DataDir should just above of manifest 00126 strcat(pFM->sDataDir,pFM->manifest.sScribbleName); 00127 strcat(pFM->sDataDir,"/"); 00128 00129 //constract manifest 00130 strcpy(pFM->sManifestPathName,pFM->sDataDir); 00131 strcat(pFM->sManifestPathName,MANIFEST_FILENAME); 00132 00133 dumpFileManager(pFM); 00134 //init manifest. 00135 pFM->manifest.iLastOpenPage=0;//numbered from 1. 00136 pFM->manifest.iTotalPages=0; 00137 00138 pFM->bNeedCreatDirHirachy=TRUE; 00139 pFM->isCreatedFromTmpl=TRUE; 00140 00141 //construct the first new page. 00142 insertNewPage(pFM,1,NULL); 00143 jumptoScribPage(pFM,1); 00144 00145 return 0; 00146 }

1.5.6