00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <config.h>
00035
00036 #include <linux/limits.h>
00037 #include <stdio.h>
00038 #include <string.h>
00039 #include <stdlib.h>
00040 #include <mntent.h>
00041 #include <strings.h>
00042 #include <sys/stat.h>
00043 #include <sys/types.h>
00044 #include <unistd.h>
00045
00046 #include <sys/stat.h>
00047 #include <sys/types.h>
00048
00049 #include <glib.h>
00050 #include <gtk/gtk.h>
00051
00052 #include <liberregxml/erregapi.h>
00053 #include <libermanifest/ermanifest.h>
00054
00055 #include "contentListerLog.h"
00056 #include "lister.h"
00057 #include "erConnect.h"
00058 #include "system.h"
00059 #include "gtkPincodeScreen.h"
00060 #include "control.h"
00061 #include "stack.h"
00062 #include "metadataStoreManager.h"
00063 #include "erMdsContent.h"
00064 #include "regValue.h"
00065 #include "languages.h"
00066
00067 static GArray *g_contentArray = NULL;
00068 static stItem_t *g_rootInfo[TOTAL_STACK_COUNT];
00069
00070
00071 static void rootInfoInit(void);
00072 static void rootInfoStore(st_ContentType_e type, regContentCategory_t * theContentCategory);
00073 static void rootInfoDestroy(void);
00074
00075 static gboolean isRealPathSubFolder(const char *path, const char *basePath);
00076 static void recreateArchives(st_ContentType_e storageType);
00077 static char* getArchiveName(st_ContentType_e archiveType);
00078
00079 void mdsInit(void)
00080 {
00081
00082 mdsDestroy();
00083
00084 rootInfoInit();
00085 stackInitAll();
00086
00087 mdsRecreateArchives(st_StorageTypeMain);
00088 mdsRecreateArchives(st_StorageTypeCF);
00089 mdsRecreateArchives(st_StorageTypeSD);
00090 mdsRecreateArchives(st_StorageTypeUSB);
00091 }
00092
00093 void mdsDestroy(void)
00094 {
00095 rootInfoDestroy();
00096 stackDestroyAll();
00097
00098 if (g_contentArray)
00099 {
00100 g_array_free(g_contentArray, TRUE);
00101 g_contentArray = NULL;
00102 }
00103 }
00104
00105 int mdsScanRoot(st_ContentType_e contentType)
00106 {
00107 int result = 0;
00108 mdsSortStruct_t *sort = NULL;
00109 int sortResult;
00110
00111 CL_STACKPRINTF("");
00112
00113
00114 if (g_contentArray)
00115 {
00116 CL_STACKPRINTF("g_array_free");
00117 g_array_free(g_contentArray, TRUE);
00118 g_contentArray = NULL;
00119 }
00120
00121 CL_TIMEDISPLAY("before scan");
00122
00123 if (NULL != g_rootInfo[contentType])
00124 {
00125 result = erMdsContentScan(g_rootInfo[contentType]->dirArray, &g_contentArray);
00126 sort = &g_rootInfo[contentType]->sort;
00127 }
00128
00129 CL_TIMEDISPLAY("after scan");
00130
00131 if ((ERMDS_CONTENT_SCAN_FAILED != result) && (NULL != g_contentArray))
00132 {
00133 sortResult = erMdsContentSort(g_contentArray, sort);
00134
00135 CL_LOGPRINTF("erMdsContentSort returned %d", sortResult);
00136 }
00137 return result;
00138 }
00139
00140 int mdsScanCurrent(st_ContentType_e contentType)
00141 {
00142 stItem_t *contentInfo;
00143 int result = 0;
00144 mdsSortStruct_t *sort = NULL;
00145 int sortResult;
00146
00147 CL_STACKPRINTF("entry: contentType [%d]", contentType);
00148
00149 if (NULL == g_rootInfo[contentType])
00150 {
00151 CL_ERRORPRINTF("No g_rootInfo for contentType [%d], fallback to MODE menu", contentType);
00152 contentType = st_MenuTypeMode;
00153 }
00154 g_return_val_if_fail( (NULL != g_rootInfo[contentType]), result);
00155
00156
00157 if (g_contentArray)
00158 {
00159 CL_STACKPRINTF("g_array_free");
00160 g_array_free(g_contentArray, TRUE);
00161 g_contentArray = NULL;
00162 }
00163
00164 contentInfo = stackPeek(contentType);
00165
00166 CL_TIMEDISPLAY("before scan");
00167
00168 if (NULL == contentInfo)
00169 {
00170 CL_STACKPRINTF("=> root content");
00171 result = erMdsContentScan(g_rootInfo[contentType]->dirArray, &g_contentArray);
00172 }
00173 else
00174 {
00175
00176 stackItemDisplay(contentInfo);
00177 result = erMdsContentScan(contentInfo->dirArray, &g_contentArray);
00178 }
00179
00180 CL_TIMEDISPLAY("after scan");
00181
00182 if ((ERMDS_CONTENT_SCAN_FAILED != result) && (NULL != g_contentArray))
00183 {
00184
00185 sort = &g_rootInfo[contentType]->sort;
00186 sortResult = erMdsContentSort(g_contentArray, sort);
00187
00188 CL_LOGPRINTF("erMdsContentSort returned %d", sortResult);
00189 }
00190 return result;
00191 }
00192
00200 int mdsScanNext(st_ContentType_e contentType, char *directory, unsigned int theIndex)
00201 {
00202 stItem_t *newItem;
00203 stItem_t *currentItem;
00204 int result = 0;
00205 mdsDirectory_t folder;
00206
00207 strcpy(folder.szFilename, directory);
00208
00209 CL_STACKPRINTF("%s", folder.szFilename);
00210
00211 newItem = g_new0(stItem_t, 1);
00212 currentItem = stackPeek(contentType);
00213
00214 if (NULL == currentItem)
00215 {
00216 CL_STACKPRINTF("=> root content");
00217 currentItem = g_rootInfo[contentType];
00218 }
00219
00220
00221 newItem->dirArray = g_array_sized_new(FALSE, TRUE, ERMDS_MAX_FILENAME_SIZE, INITIAL_DIR_COUNT_ARRAY_SIZE);
00222 CL_STACKPRINTF("newItem->dirArray 0x%x", (unsigned int) newItem->dirArray);
00223 g_array_append_val(newItem->dirArray, folder);
00224
00225
00226
00227
00228
00229
00230 newItem->index = 0;
00231
00232
00233 stackPush(contentType, newItem);
00234
00235
00236 g_free(newItem);
00237
00238 result = mdsScanCurrent(contentType);
00239 return result;
00240 }
00241
00246 int mdsScanPrevious(st_ContentType_e contentType)
00247 {
00248 int result = 0;
00249
00250 CL_STACKPRINTF("");
00251
00252 stackPop(contentType);
00253 result = mdsScanCurrent(contentType);
00254 return result;
00255 }
00256
00257
00258 int mdsGetItemCount(void)
00259 {
00260
00261 if (g_contentArray)
00262 {
00263 CL_STACKPRINTF("%d", g_contentArray->len);
00264 return g_contentArray->len;
00265 }
00266 else
00267 {
00268 CL_STACKPRINTF("0");
00269 return 0;
00270 }
00271 }
00272
00273
00274 int mdsGetItemIndex(const gchar* szFilename)
00275 {
00276 int i;
00277 int index = -1;
00278 gboolean found;
00279 mdsFsItem_t *pFsItem;
00280 char *cp;
00281 char szRealpath[PATH_MAX];
00282
00283 g_return_val_if_fail((g_contentArray != NULL), -1);
00284
00285 for ( i = 0, found = FALSE ;
00286 i < g_contentArray->len && !found ;
00287 i++ )
00288 {
00289 pFsItem = &g_array_index(g_contentArray, mdsFsItem_t, i);
00290 cp = realpath(pFsItem->szFilename, szRealpath);
00291 if (cp != NULL)
00292 {
00293 if (strcmp(szFilename, szRealpath) == 0 )
00294 {
00295 found = TRUE;
00296 index = i;
00297 }
00298 }
00299 }
00300
00301 return index;
00302 }
00303
00304
00305 gboolean mdsGetItemFilename(int index, gchar* szFilename, int len)
00306 {
00307 mdsFsItem_t *pFsItem = NULL;
00308
00309 g_return_val_if_fail((g_contentArray != NULL), FALSE);
00310 g_return_val_if_fail( ((index >= 0) && (index < g_contentArray->len)) , FALSE);
00311 g_return_val_if_fail((szFilename != NULL), FALSE);
00312
00313 pFsItem = &g_array_index(g_contentArray, mdsFsItem_t, index);
00314 g_return_val_if_fail((pFsItem != NULL), FALSE);
00315 snprintf(szFilename, len, "%s", pFsItem->szFilename);
00316
00317 return TRUE;
00318 }
00319
00320
00321 int mdsSetPageContent(clDisplayItem_t * displayItemArray, int nBegin, int *nChunk)
00322 {
00323 int returnValue;
00324
00325 if (g_contentArray)
00326 {
00327 CL_TIMEDISPLAY("before erClGetDisplayItems");
00328
00329 returnValue = erClGetDisplayItems(g_contentArray, nBegin, nChunk, displayItemArray);
00330
00331 CL_TIMEDISPLAY("after erClGetDisplayItems");
00332
00333 }
00334 else
00335 {
00336 CL_ERRORPRINTF("g_contentArray == NULL");
00337 returnValue = (-1);
00338 }
00339
00340 return returnValue;
00341 }
00342
00343
00344
00345 void mdsSetIndex(st_ContentType_e contentType, unsigned int index)
00346 {
00347 stItem_t *theItem;
00348
00349 theItem = stackPeek(contentType);
00350
00351 if (NULL != theItem)
00352 {
00353
00354 theItem->index = index;
00355 }
00356 else
00357 {
00358
00359 if (NULL != g_rootInfo[contentType])
00360 {
00361 g_rootInfo[contentType]->index = index;
00362 }
00363 }
00364 return;
00365 }
00366
00367
00368
00369 unsigned int mdsGetIndex(st_ContentType_e contentType)
00370 {
00371 unsigned int returnValue = 0;
00372 stItem_t *theItem;
00373
00374 theItem = stackPeek(contentType);
00375
00376 if (NULL != theItem)
00377 {
00378 returnValue = theItem->index;
00379 }
00380 else
00381 {
00382 if (NULL != g_rootInfo[contentType])
00383 {
00384 returnValue = g_rootInfo[contentType]->index;
00385 }
00386 }
00387 return returnValue;
00388 }
00389
00390 static void rootInfoInit(void)
00391 {
00392 regContentCategory_t *theBooks = NULL, *theNews = NULL, *theDocs = NULL, *theNotes = NULL;
00393 regContentCategory_t *theMain = NULL, *theCF = NULL, *theSD = NULL, *theUSB = NULL;
00394 regContentCategory_t *theRecent = NULL, *theDownload = NULL, *theSearch = NULL, *theMode = NULL;
00395
00396 gchar *cp;
00397 struct stat statbuf;
00398
00399
00400 theBooks = erRegGetContentCategory(BOOKS_CATEGORY);
00401 theNews = erRegGetContentCategory(NEWSPAPERS_CATEGORY);
00402 theDocs = erRegGetContentCategory(DOCUMENTS_CATEGORY);
00403 theNotes = erRegGetContentCategory(NOTES_CATEGORY);
00404
00405 theMode = erRegGetContentCategory(MODE_CATEGORY);
00406
00407 theCF = erRegGetContentCategory(CF_CATEGORY);
00408 theSD = erRegGetContentCategory(SD_CATEGORY);
00409 theUSB = erRegGetContentCategory(USB_CATEGORY);
00410 theMain = erRegGetContentCategory(MAIN_CATEGORY);
00411
00412 theDownload = erRegGetContentCategory(DOWNLOAD_HISTORY);
00413 theSearch = erRegGetContentCategory(SEARCH_RESULT);
00414 theRecent = erRegGetContentCategory(RECENTDOCUMENTS);
00415
00416 if (theBooks)
00417 {
00418 rootInfoStore(st_ContentTypeBooks, theBooks);
00419 erRegFreeContentCategory(theBooks);
00420 }
00421 else
00422 {
00423 CL_ERRORPRINTF("BOOKS_CATEGORY registry info missing");
00424 }
00425
00426 if (theNews)
00427 {
00428 rootInfoStore(st_ContentTypeNews, theNews);
00429 erRegFreeContentCategory(theNews);
00430 }
00431 else
00432 {
00433 CL_ERRORPRINTF("NEWSPAPERS_CATEGORY registry info missing");
00434 }
00435
00436 if (theDocs)
00437 {
00438 rootInfoStore(st_ContentTypeDocs, theDocs);
00439 erRegFreeContentCategory(theDocs);
00440 }
00441 else
00442 {
00443 CL_ERRORPRINTF("DOCUMENTS_CATEGORY registry info missing");
00444 }
00445
00446 if (theNotes)
00447 {
00448 rootInfoStore(st_ContentTypeNotes, theNotes);
00449 erRegFreeContentCategory(theNotes);
00450 }
00451 else
00452 {
00453 CL_ERRORPRINTF("NOTES_CATEGORY registry info missing");
00454 }
00455
00456 if (theMode)
00457 {
00458 if (theMode->location)
00459 {
00460 cp = g_strconcat(theMode->location, "/", languagesGetCountry(), NULL);
00461 if (stat(cp, &statbuf) != 0)
00462 {
00463 g_free(cp);
00464 cp = g_strconcat(theMode->location, "/", languagesGetDefaultCountry(), NULL);
00465 }
00466 g_free(theMode->location);
00467 theMode->location = cp;
00468 CL_STACKPRINTF("MODE_CATEGORY location changed: %s", theMode->location);
00469 }
00470
00471 rootInfoStore(st_MenuTypeMode, theMode);
00472 erRegFreeContentCategory(theMode);
00473 }
00474 else
00475 {
00476 CL_ERRORPRINTF("MODE_CATEGORY registry info missing");
00477 }
00478
00479 if (theCF)
00480 {
00481 rootInfoStore(st_StorageTypeCF, theCF);
00482 erRegFreeContentCategory(theCF);
00483 }
00484 else
00485 {
00486 CL_ERRORPRINTF("CF_CATEGORY registry info missing");
00487 }
00488
00489 if (theSD)
00490 {
00491 rootInfoStore(st_StorageTypeSD, theSD);
00492 erRegFreeContentCategory(theSD);
00493 }
00494 else
00495 {
00496 CL_ERRORPRINTF("SD_CATEGORY registry info missing");
00497 }
00498
00499 if (theUSB)
00500 {
00501 rootInfoStore(st_StorageTypeUSB, theUSB);
00502 erRegFreeContentCategory(theUSB);
00503 }
00504 else
00505 {
00506 CL_ERRORPRINTF("USB_CATEGORY registry info missing");
00507 }
00508
00509 if (theMain)
00510 {
00511 rootInfoStore(st_StorageTypeMain, theMain);
00512 erRegFreeContentCategory(theMain);
00513 }
00514 else
00515 {
00516 CL_ERRORPRINTF("MAIN_CATEGORY registry info missing");
00517 }
00518
00519 if (theDownload)
00520 {
00521 rootInfoStore(st_DownloadHistory, theDownload);
00522 erRegFreeContentCategory(theDownload);
00523 }
00524 else
00525 {
00526 CL_ERRORPRINTF("DOWNLOAD_HISTORY registry info missing");
00527 }
00528
00529 if (theSearch)
00530 {
00531 rootInfoStore(st_SearchResult, theSearch);
00532 erRegFreeContentCategory(theSearch);
00533 }
00534 else
00535 {
00536 CL_ERRORPRINTF("SEARCH_RESULT registry info missing");
00537 }
00538
00539 if (theRecent)
00540 {
00541 rootInfoStore(st_RecentDocuments, theRecent);
00542 erRegFreeContentCategory(theRecent);
00543 }
00544 else
00545 {
00546 CL_ERRORPRINTF("RECENTDOCUMENTS registry info missing");
00547 }
00548 }
00549
00550 static void rootInfoStore(st_ContentType_e type, regContentCategory_t * theContentCategory)
00551 {
00552 unsigned int index;
00553 mdsDirectory_t dir;
00554 stItem_t *rootItem;
00555
00556
00557 rootItem = g_new0(stItem_t, 1);
00558
00559 if (theContentCategory->location)
00560 {
00561 rootItem->dirArray = g_array_sized_new(FALSE, TRUE, sizeof(mdsDirectory_t), 1);
00562
00563 for (index = 0; index < 1; index++)
00564 {
00565 strncpy(dir.szFilename, theContentCategory->location, ERMDS_MAX_FILENAME_SIZE);
00566 g_array_append_val(rootItem->dirArray, dir);
00567 CL_STACKPRINTF("root dir %s", dir.szFilename);
00568 }
00569 }
00570
00571 rootItem->sort.ascending = theContentCategory->sortAscending;
00572 rootItem->sort.ft = getFieldType(theContentCategory->sortFieldType);
00573
00574 rootItem->index = 0;
00575
00576 stackItemDisplay(rootItem);
00577
00578 g_rootInfo[type] = rootItem;
00579 }
00580
00581
00582 mdsSortStruct_t* mdsGetSortStructOfRootInfo(st_ContentType_e type)
00583 {
00584 stItem_t *rootItem = NULL;
00585
00586 if (type < st_ContentTypeBooks || type >= st_ContentTypeUndefined || type >= TOTAL_STACK_COUNT)
00587 {
00588 CL_ERRORPRINTF("Invalid arguments");
00589 return NULL;
00590 }
00591
00592 rootItem = g_rootInfo[type];
00593 if (rootItem)
00594 {
00595 return &(rootItem->sort);
00596 }
00597 else
00598 {
00599 CL_WARNPRINTF("Can't find the rootItem of type%d", type);
00600 return NULL;
00601 }
00602 }
00603
00604 void mdsSetSortStructOfRootInfo(st_ContentType_e type, const mdsSortStruct_t* sort)
00605 {
00606 stItem_t *rootItem = NULL;
00607 mdsSortStruct_t *localSort = NULL;
00608
00609 if (type < st_ContentTypeBooks || type >= st_ContentTypeUndefined || type >= TOTAL_STACK_COUNT || NULL == sort)
00610 {
00611 CL_ERRORPRINTF("Invalid arguments");
00612 return;
00613 }
00614
00615 rootItem = g_rootInfo[type];
00616 if (rootItem)
00617 {
00618 localSort = &(rootItem->sort);
00619 localSort->ascending = sort->ascending;
00620 localSort->ft = sort->ft;
00621 }
00622 else
00623 {
00624 CL_WARNPRINTF("Can't find the rootItem of type%d", type);
00625 return;
00626 }
00627 }
00628
00629 char* getFieldString(mdsFieldType_e type)
00630 {
00631 static char string[ERCL_MAX_FIELDNAME_SIZE+1];
00632
00633 switch (type)
00634 {
00635 case mdsFieldAuthor:
00636 strcpy(string, AUTHOR);
00637 break;
00638 case mdsFieldDate:
00639 strcpy(string, DATE);
00640 break;
00641 case mdsFieldDescription:
00642 strcpy(string, DESCRIPTION);
00643 break;
00644 case mdsFieldFile:
00645 strcpy(string, FIELDFILE);
00646 break;
00647 case mdsFieldTitle:
00648 strcpy(string, TITLE);
00649 break;
00650 case mdsFieldFsName:
00651 strcpy(string, FSNAME);
00652 break;
00653 case mdsFieldExtName:
00654 strcpy(string, EXTENSION);
00655 break;
00656 case mdsFieldSize:
00657 strcpy(string, SIZE);
00658 break;
00659 case mdsFieldNone:
00660 default:
00661 string[0] = '\0';
00662 break;
00663 }
00664 return string;
00665 }
00666
00667 mdsFieldType_e getFieldType(char *stringValue)
00668 {
00669 if (stringValue)
00670 {
00671
00672 if (strcmp(stringValue, AUTHOR) == 0)
00673 {
00674 return mdsFieldAuthor;
00675 }
00676 else if (strcmp(stringValue, DATE) == 0)
00677 {
00678 return mdsFieldDate;
00679 }
00680 else if (strcmp(stringValue, FIELDFILE) == 0)
00681 {
00682 return mdsFieldFile;
00683 }
00684 else if (strcmp(stringValue, FSNAME) == 0)
00685 {
00686 return mdsFieldFsName;
00687 }
00688 else if (strcmp(stringValue, TITLE) == 0)
00689 {
00690 return mdsFieldTitle;
00691 }
00692 else if (strcmp(stringValue, DESCRIPTION) == 0)
00693 {
00694 return mdsFieldDescription;
00695 }
00696 else if (strcmp(stringValue, EXTENSION) == 0)
00697 {
00698 return mdsFieldExtName;
00699 }
00700 else if (strcmp(stringValue, SIZE) == 0)
00701 {
00702 return mdsFieldSize;
00703 }
00704 else
00705 {
00706 return mdsFieldNone;
00707 }
00708 }
00709 else
00710 {
00711 return mdsFieldNone;
00712 }
00713
00714 }
00715
00716 gchar* getContentCategoryID(st_ContentType_e type)
00717 {
00718 static gchar szID[ERMDS_MAX_EXTENSION_ID_SIZE+1] = "";
00719
00720 switch (type)
00721 {
00722 case st_ContentTypeBooks:
00723 strcpy(szID, BOOKS_CATEGORY);
00724 break;
00725 case st_ContentTypeNews:
00726 strcpy(szID, NEWSPAPERS_CATEGORY);
00727 break;
00728 case st_ContentTypeNotes:
00729 strcpy(szID, NOTES_CATEGORY);
00730 break;
00731 case st_ContentTypeDocs:
00732 strcpy(szID, DOCUMENTS_CATEGORY);
00733 break;
00734 case st_StorageTypeCF:
00735 strcpy(szID, CF_CATEGORY);
00736 break;
00737 case st_StorageTypeMain:
00738 strcpy(szID, MAIN_CATEGORY);
00739 break;
00740 case st_StorageTypeSD:
00741 strcpy(szID, SD_CATEGORY);
00742 break;
00743 case st_StorageTypeUSB:
00744 strcpy(szID, USB_CATEGORY);
00745 break;
00746 case st_MenuTypeMode:
00747 strcpy(szID, MODE_CATEGORY);
00748 break;
00749 case st_DownloadHistory:
00750 strcpy(szID, DOWNLOAD_HISTORY);
00751 break;
00752 case st_SearchResult:
00753 strcpy(szID, SEARCH_RESULT);
00754 break;
00755 case st_RecentDocuments:
00756 strcpy(szID, RECENTDOCUMENTS);
00757 break;
00758 case st_ContentTypeUndefined:
00759 default:
00760 szID[0] = '\0';
00761 break;
00762 }
00763 return szID;
00764 }
00765
00766 static void rootInfoDestroy(void)
00767 {
00768 int index;
00769
00770 for (index = 0; index < TOTAL_STACK_COUNT; index++)
00771 {
00772 if (g_rootInfo[index])
00773 {
00774 stackItemDestroy(g_rootInfo[index]);
00775 g_rootInfo[index] = NULL;
00776 }
00777 }
00778 }
00779
00780 int mdsGetRootLocation(const st_ContentType_e contentType, char * location, const int length)
00781 {
00782 int nRet = 0;
00783 char* cp;
00784 char szRealpath[PATH_MAX];
00785
00786 if (NULL == location || 0 >= length)
00787 {
00788 CL_ERRORPRINTF("Invalid buffer pointer or length!");
00789 return nRet;
00790 }
00791
00792 if ((NULL == g_rootInfo[contentType]) || (NULL == g_rootInfo[contentType]->dirArray))
00793 {
00794 if (contentType == st_MenuTypeMode)
00795 {
00796 CL_ERRORPRINTF("No root dir specified for st_MenuTypeMode!");
00797 return nRet;
00798 }
00799 else
00800 {
00801 CL_ERRORPRINTF("No root dir for contentType [%d], fallback to MODE menu", contentType);
00802 return mdsGetRootLocation(st_MenuTypeMode, location, length);
00803 }
00804 }
00805
00806 mdsDirectory_t *directory = &g_array_index(g_rootInfo[contentType]->dirArray, mdsDirectory_t, 0);
00807 if (directory)
00808 {
00809 cp = realpath(directory->szFilename, szRealpath);
00810 if (cp == NULL)
00811 {
00812
00813 cp = directory->szFilename;
00814 }
00815 nRet = snprintf(location, length, "%s", cp);
00816 }
00817 else
00818 {
00819 CL_ERRORPRINTF("Invalid directory pointer!");
00820 }
00821 return nRet;
00822 }
00823
00824
00825 gboolean mdsArcLocIsChanged(st_ContentType_e archiveType, st_ContentType_e storageType)
00826 {
00827 char archiveDirName[ERMDS_MAX_FILENAME_SIZE], storageDirName[ERMDS_MAX_FILENAME_SIZE];
00828 gboolean bRet = FALSE;
00829
00830 if ((archiveType != st_ContentTypeNews)
00831 && (archiveType != st_ContentTypeBooks)
00832 && (archiveType != st_ContentTypeDocs)
00833 && (archiveType != st_ContentTypeNotes))
00834 {
00835 CL_ERRORPRINTF("invalid archive type[%d]", archiveType);
00836 return bRet;
00837 }
00838 if ((storageType != st_StorageTypeCF)
00839 && (storageType != st_StorageTypeSD)
00840 && (storageType != st_StorageTypeUSB)
00841 && (storageType != st_StorageTypeMain))
00842 {
00843 CL_ERRORPRINTF("invalid storage type[%d]", storageType);
00844 return bRet;
00845 }
00846
00847 if ( mdsGetRootLocation(archiveType, archiveDirName, sizeof(archiveDirName)) > 0 )
00848 {
00849 if ( mdsGetRootLocation(storageType, storageDirName, sizeof(storageDirName)) > 0 )
00850 {
00851 CL_LOGPRINTF("%s,%s", archiveDirName, storageDirName);
00852 if (isRealPathSubFolder(archiveDirName, storageDirName))
00853 {
00854 bRet = TRUE;
00855 }
00856 }
00857 else
00858 {
00859 CL_ERRORPRINTF("error");
00860 }
00861 }
00862 else
00863 {
00864 CL_ERRORPRINTF("error");
00865 }
00866 return bRet;
00867 }
00868
00869
00870
00871
00872
00873 void mdsRecreateArchives(st_ContentType_e storageType)
00874 {
00875 CL_LOGPRINTF("entry");
00876
00877
00878 if ( (storageType != st_StorageTypeCF) && (storageType != st_StorageTypeSD)
00879 && (storageType != st_StorageTypeUSB) && (storageType != st_StorageTypeMain) )
00880 {
00881 CL_ERRORPRINTF("invalid storage type[%d]", storageType);
00882 return;
00883 }
00884
00885 if (st_StorageTypeMain == storageType)
00886 {
00887
00888
00889 recreateArchives(st_StorageTypeMain);
00890 }
00891 else
00892 {
00893
00894
00895 if ( mdsArcLocIsChanged(st_ContentTypeNews, storageType)
00896 || mdsArcLocIsChanged(st_ContentTypeBooks, storageType)
00897 || mdsArcLocIsChanged(st_ContentTypeDocs, storageType)
00898 || mdsArcLocIsChanged(st_ContentTypeNotes, storageType) )
00899 {
00900 recreateArchives(storageType);
00901 }
00902 }
00903 }
00904
00905 static gboolean isRealPathSubFolder(const char *path, const char *basePath)
00906 {
00907 char *cp1 = NULL, *cp2 = NULL;
00908 char realPath[ERMDS_MAX_FILENAME_SIZE], realBasePath[ERMDS_MAX_FILENAME_SIZE];
00909 gboolean bRet = FALSE;
00910
00911 cp1 = realpath(path, realPath);
00912 cp2 = realpath(basePath, realBasePath);
00913
00914 CL_LOGPRINTF("%s,%s", path, realPath);
00915 CL_LOGPRINTF("cp1=%s, cp2=%s", cp1, cp2);
00916 CL_LOGPRINTF("%s,%s", realPath, realBasePath);
00917
00918 if (strstr(realPath, realBasePath) != NULL)
00919 {
00920 CL_LOGPRINTF("realpath of %s is subfolder of realpath of %s", path, basePath);
00921 bRet = TRUE;
00922 }
00923 else
00924 {
00925 CL_LOGPRINTF("realpath of %s is not subfolder of realpath of %s", path, basePath);
00926 }
00927
00928 return bRet;
00929 }
00930
00931 static void recreateArchives(st_ContentType_e storageType)
00932 {
00933 char storageDirName[ERMDS_MAX_FILENAME_SIZE];
00934 char newDir[ERMDS_MAX_FILENAME_SIZE];
00935 char *cp = NULL;
00936
00937 if (!storageIsMounted(storageType))
00938 {
00939 CL_ERRORPRINTF("storage not mounted, storage type[%d]", storageType);
00940 return;
00941 }
00942
00943 if ( mdsGetRootLocation(storageType, storageDirName, sizeof(storageDirName)) > 0 )
00944 {
00945 CL_LOGPRINTF("recreate archives on %s", storageDirName);
00946
00947
00948 cp = getArchiveName(st_ContentTypeNews);
00949 if (cp)
00950 {
00951 snprintf(newDir, ERMDS_MAX_FILENAME_SIZE, "%s%s", storageDirName, cp);
00952 if (0 != mkdir(newDir, 0755))
00953 {
00954 CL_ERRORPRINTF("Can not create directory %s!", newDir);
00955 }
00956 }
00957
00958
00959 cp = getArchiveName(st_ContentTypeBooks);
00960 if (cp)
00961 {
00962 snprintf(newDir, ERMDS_MAX_FILENAME_SIZE, "%s%s", storageDirName, cp);
00963 if (0 != mkdir(newDir, 0755))
00964 {
00965 CL_ERRORPRINTF("Can not create directory %s!", newDir);
00966 }
00967 }
00968
00969
00970 cp = getArchiveName(st_ContentTypeDocs);
00971 if (cp)
00972 {
00973 snprintf(newDir, ERMDS_MAX_FILENAME_SIZE, "%s%s", storageDirName, cp);
00974 if (0 != mkdir(newDir, 0755))
00975 {
00976 CL_ERRORPRINTF("Can not create directory %s!", newDir);
00977 }
00978 }
00979
00980
00981 cp = getArchiveName(st_ContentTypeNotes);
00982 if (cp)
00983 {
00984 snprintf(newDir, ERMDS_MAX_FILENAME_SIZE, "%s%s", storageDirName, cp);
00985 if (0 != mkdir(newDir, 0755))
00986 {
00987 CL_ERRORPRINTF("Can not create directory %s!", newDir);
00988 }
00989 }
00990 }
00991 }
00992
00993 static char* getArchiveName(st_ContentType_e archiveType)
00994 {
00995 mdsDirectory_t *directory = NULL;
00996 char* cp = NULL;
00997
00998 if ((archiveType != st_ContentTypeNews)
00999 && (archiveType != st_ContentTypeBooks)
01000 && (archiveType != st_ContentTypeDocs)
01001 && (archiveType != st_ContentTypeNotes))
01002 {
01003 CL_ERRORPRINTF("invalid archive type[%d]", archiveType);
01004 return NULL;
01005 }
01006
01007 if ( g_rootInfo[archiveType] && g_rootInfo[archiveType]->dirArray)
01008 {
01009 directory = &g_array_index(g_rootInfo[archiveType]->dirArray, mdsDirectory_t, 0);
01010 if (directory && directory->szFilename)
01011 {
01012 cp = strrchr(directory->szFilename, '/');
01013 }
01014 }
01015
01016 CL_LOGPRINTF("%s", cp);
01017 return cp;
01018 }
01019
01020
01021 gboolean storageIsMounted(st_ContentType_e storageType)
01022 {
01023 CL_LOGPRINTF("entry");
01024
01025 gboolean found = FALSE;
01026
01027 char storageDirName[ERMDS_MAX_FILENAME_SIZE];
01028
01029 if ( mdsGetRootLocation(storageType, storageDirName, sizeof(storageDirName)) > 0 )
01030 {
01031 char *cp = NULL;
01032 char realPath[ERMDS_MAX_FILENAME_SIZE];
01033
01034 cp = realpath(storageDirName, realPath);
01035 CL_LOGPRINTF("%s,%s", storageDirName, realPath);
01036
01037 FILE *fp = setmntent("/proc/mounts", "r");
01038 struct mntent* mt = NULL;
01039
01040 while ((mt = getmntent(fp)))
01041 {
01042 CL_LOGPRINTF("Partition: %s: %s %s", mt->mnt_fsname, mt->mnt_dir, mt->mnt_type);
01043
01044 if (strcasecmp(mt->mnt_dir, realPath) == 0)
01045 {
01046 if ( strcasecmp(mt->mnt_type, "vfat") == 0 )
01047 {
01048 found = TRUE;
01049 break;
01050 }
01051 else
01052 {
01053 found = FALSE;
01054 }
01055 }
01056 }
01057
01058 endmntent(fp);
01059 }
01060 else
01061 {
01062 CL_ERRORPRINTF("can't get the path of storageType[%d]", storageType);
01063 }
01064
01065 CL_LOGPRINTF("found[%d]", found);
01066 return found;
01067 }
01068
01070
01071 void displayScanResult(void)
01072 {
01073 int i;
01074 mdsFsItem_t *pFsItem;
01075
01076 for (i = 0; i < g_contentArray->len; i++)
01077 {
01078 pFsItem = &g_array_index(g_contentArray, mdsFsItem_t, i);
01079 printf("%d. Name: %s", i, pFsItem->szFilename);
01080 printf("\ttype: %d\n", (int) pFsItem->fit);
01081 }
01082 }