misc/libphyslayer/hwpacksmounter.c
branch0.9.24
changeset 13393 ae5d6448c5be
parent 8978 e6ef8fe314bd
child 13395 fa81f809fbb9
equal deleted inserted replaced
13346:e461deddc942 13393:ae5d6448c5be
    35 }
    35 }
    36 
    36 
    37 PHYSFS_DECL void hedgewarsMountPackage(char * fileName)
    37 PHYSFS_DECL void hedgewarsMountPackage(char * fileName)
    38 {
    38 {
    39     int fileNameLength = strlen(fileName);
    39     int fileNameLength = strlen(fileName);
       
    40     int dirLength = 0;
    40     if (fileNameLength > 4)
    41     if (fileNameLength > 4)
    41         if (strcmp(fileName + fileNameLength - 4, ".hwp") == 0)
    42         if (strcmp(fileName + fileNameLength - 4, ".hwp") == 0)
    42         {
    43         {
    43             const char * dir = PHYSFS_getRealDir(fileName);
    44             const char * dir = PHYSFS_getRealDir(fileName);
    44             if(dir)
    45             if(dir)
    45             {
    46             {
    46                 char * fullPath = (char *)malloc(strlen(dir) + fileNameLength + 2);
    47 				dirLength = strlen(dir);
    47                 strcpy(fullPath, dir);
    48 				if (dirLength > 4)
    48                 strcat(fullPath, "/");
    49 				{
    49                 strcat(fullPath, fileName);
    50 					if (strcmp(dir + dirLength - 4, ".hwp") == 0)
       
    51 					{
       
    52 						char * uniqName = (char *)malloc(strlen(dir) + fileNameLength + 2);
       
    53 						strcpy(uniqName, dir);
       
    54 						strcat(uniqName, ",");
       
    55 						strcat(uniqName, fileName);
       
    56 						PHYSFS_mountHandle(PHYSFS_openRead(fileName), uniqName, NULL, 0);
       
    57 						free(uniqName);
       
    58 					}
       
    59 					else
       
    60 					{
       
    61 						char * fullPath = (char *)malloc(strlen(dir) + fileNameLength + 2);
       
    62 						strcpy(fullPath, dir);
       
    63 						strcat(fullPath, "/");
       
    64 						strcat(fullPath, fileName);
    50 
    65 
    51                 PHYSFS_mount(fullPath, NULL, 0);
    66 						PHYSFS_mount(fullPath, NULL, 0);
    52 
    67 
    53                 free(fullPath);
    68 						free(fullPath);
       
    69 					}
       
    70 				}
    54             }
    71             }
    55         }
    72         }
    56 }
    73 }