Previous 15994 Revisions Next

r3044 Saturday 16th August, 2008 at 03:12:14 UTC by Nathan Woods
Fixed some bugginess in the new file manager (when getting deeper into zip
paths)
[src/mess]image.c zippath.c zippath.h

src/mess/image.c
r3043r3044
2222#include "mamecore.h"
2323#include "messopts.h"
2424#include "ui.h"
25#include "zippath.h"
2526
2627
2728
r3043r3044
811812   if (ziperr == ZIPERR_NONE)
812813   {
813814      /* iterate through the zip file */
814      header = zip_file_first_file(zip);
815      header = zippath_find_sub_path(zip, zip_entry, NULL);
815816
816      /* if we specified a zip partial path, find it */
817      if (zip_entry != NULL)
818      {
819         while(header != NULL)
820         {
821            if (!mame_stricmp(header->filename, zip_entry))
822               break;
823            header = zip_file_next_file(zip);
824         }
825      }
826
827817      /* were we successful? */
828818      if (header != NULL)
829819      {
src/mess/zippath.c
r3043r3044
179179
180180
181181/*-------------------------------------------------
182    is_zip_separator - special check for path
183   separators
184-------------------------------------------------*/
185
186static int is_zip_separator(char c)
187{
188   return (c == '/') || osd_is_path_separator(c);
189}
190
191
192
193/*-------------------------------------------------
194    zippath_find_sub_path - attempts to identify the
195   type of a sub path in a zip file
196-------------------------------------------------*/
197
198const zip_file_header *zippath_find_sub_path(zip_file *zipfile, const char *subpath, osd_dir_entry_type *type)
199{
200   int i, j;
201   const zip_file_header *header;
202
203   for (header = zip_file_first_file(zipfile); header != NULL; header = zip_file_next_file(zipfile))
204   {
205      /* special case */
206      if (subpath == NULL)
207      {
208         if (type != NULL)
209            *type = ENTTYPE_FILE;
210         return header;
211      }
212
213      i = 0;
214      j = 0;
215      do
216      {
217         while(header->filename[i] == '/')
218            i++;
219         while(is_zip_separator(subpath[j]))
220            j++;
221         while((header->filename[i] != '\0') && (tolower(header->filename[i]) == tolower(subpath[j])))
222         {
223            i++;
224            j++;
225         }
226      }
227      while((header->filename[i] == '/') && is_zip_separator(subpath[j]));
228
229      if (subpath[j] == '\0')
230      {
231         if (header->filename[i] == '\0')
232         {
233            if (type != NULL)
234               *type = ENTTYPE_FILE;
235            return header;
236         }
237         else if ((i == 0) || (header->filename[i] == '/'))
238         {
239            if (type != NULL)
240               *type = ENTTYPE_DIR;
241            return header;
242         }
243      }
244   }
245
246   if (type != NULL)
247      *type = ENTTYPE_NONE;
248   return NULL;
249}
250
251
252
253/*-------------------------------------------------
182254    zippath_resolve - separates a ZIP path out into
183255   true path and ZIP entry components
184256-------------------------------------------------*/
r3043r3044
209281
210282      /* stat the path */
211283      current_entry = osd_stat(astring_c(apath_trimmed));
212      if (current_entry == NULL)
284
285      /* did we find anything? */
286      if (current_entry != NULL)
213287      {
214         err = FILERR_FAILURE;
215         goto done;
288         /* get the entry type and free the stat entry */
289         current_entry_type = current_entry->type;
290         free(current_entry);
291         current_entry = NULL;
216292      }
217
218      /* get the entry type and free the stat entry */
219      current_entry_type = current_entry->type;
220      free(current_entry);
221      current_entry = NULL;
222
223      /* if we have not found the file or directory, go up */
224      if (current_entry_type == ENTTYPE_NONE)
293      else
225294      {
295         /* if we have not found the file or directory, go up */
296         current_entry_type = ENTTYPE_NONE;
226297         went_up = TRUE;
227298         parent = zippath_parent(astring_alloc(), astring_c(apath));
228299         astring_free(apath);
r3043r3044
242313   if ((current_entry_type == ENTTYPE_FILE) && is_zip_file(astring_c(apath_trimmed))
243314      && (zip_file_open(astring_c(apath_trimmed), zipfile) == ZIPERR_NONE))
244315   {
245      /* this was a true ZIP path - copy out the sub path */
316      /* this was a true ZIP path - attempt to identify the type of path */
317      zippath_find_sub_path(*zipfile, path + astring_len(apath), &current_entry_type);
318      if (current_entry_type == ENTTYPE_NONE)
319      {
320         err = FILERR_NOT_FOUND;
321         goto done;
322      }
246323      astring_cpyc(newpath, path + astring_len(apath));
247      *entry_type = (astring_len(newpath) == 0) || (astring_c(newpath)[astring_len(newpath)-1] == '/')
248         ? ENTTYPE_DIR : ENTTYPE_FILE;
249324   }
250325   else
251326   {
r3043r3044
256331         goto done;
257332      }
258333      astring_cpyc(newpath, path);
259      *entry_type = current_entry_type;
260334   }
261335
262336   /* success! */
337   *entry_type = current_entry_type;
263338   err = FILERR_NONE;
264339
265340done:
r3043r3044
384459      && !strncmp(astring_c(directory->zipprefix), header->filename, len))
385460   {
386461      result = &header->filename[len];
462      while(*result == '/')
463         result++;
387464   }
388465
389466   return result;
src/mess/zippath.h
r3043r3044
1313
1414#include "corefile.h"
1515#include "astring.h"
16#include "unzip.h"
1617
1718
1819/***************************************************************************
r3043r3044
2829***************************************************************************/
2930
3031
32/* ----- zip support ----- */
33
34/* attempts to identify the   type of a sub path in a zip file */
35const zip_file_header *zippath_find_sub_path(zip_file *zipfile, const char *subpath, osd_dir_entry_type *type);
36
3137/* ----- path operations ----- */
3238
3339/* retrieves the parent directory */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team