part 1 of cleaning up my little array macro library to be a formal API. also removed...
[blender.git] / source / blender / blenkernel / intern / packedFile.c
index 02b0f6a45a01f57379d907086312fca99edd3f37..0de97b9c703733efe9b158826466a0b40e75be12 100644 (file)
 #include "BKE_packedFile.h"
 #include "BKE_report.h"
 
+#ifdef _WIN32
+#define open _open
+#define close _close
+#define read _read
+#define write _write
+#endif
+
+
 int seekPackedFile(PackedFile *pf, int offset, int whence)
 {
        int oldseek = -1, seek = 0;
@@ -123,7 +131,7 @@ int countPackedFiles(Main *bmain)
 {
        Image *ima;
        VFont *vf;
-       bSample *sample;
+       bSound *sound;
        int count = 0;
        
        // let's check if there are packed files...
@@ -135,10 +143,9 @@ int countPackedFiles(Main *bmain)
                if(vf->packedfile)
                        count++;
 
-       if(samples)
-               for(sample=samples->first; sample; sample=sample->id.next)
-                       if(sample->packedfile)
-                               count++;
+       for(sound=bmain->sound.first; sound; sound=sound->id.next)
+               if(sound->packedfile)
+                       count++;
 
        return count;
 }
@@ -208,8 +215,8 @@ void packAll(Main *bmain, ReportList *reports)
 {
        Image *ima;
        VFont *vf;
-       bSample *sample;
-       
+       bSound *sound;
+
        for(ima=bmain->image.first; ima; ima=ima->id.next)
                if(ima->packedfile == NULL)
                        ima->packedfile = newPackedFile(reports, ima->name);
@@ -218,10 +225,9 @@ void packAll(Main *bmain, ReportList *reports)
                if(vf->packedfile == NULL)
                        vf->packedfile = newPackedFile(reports, vf->name);
 
-       if(samples)
-               for(sample=samples->first; sample; sample=sample->id.next)
-                       if(sample->packedfile == NULL)
-                               sound_set_packedfile(sample, newPackedFile(reports, sample->name));
+       for(sound=bmain->sound.first; sound; sound=sound->id.next)
+               if(sound->packedfile == NULL)
+                       sound->packedfile = newPackedFile(reports, sound->name);
 }
 
 
@@ -230,7 +236,7 @@ void packAll(Main *bmain, ReportList *reports)
 // attempt to create a function that generates an unique filename
 // this will work when all funtions in fileops.c understand relative filenames...
 
-char *find_new_name(char *name)
+static char *find_new_name(char *name)
 {
        char tempname[FILE_MAXDIR + FILE_MAXFILE];
        char *newname;
@@ -360,6 +366,8 @@ int checkPackedFile(char *filename, PackedFile *pf)
                                        }
                                }
                        }
+                       
+                       close(file);
                }
        }
        
@@ -454,28 +462,26 @@ int unpackVFont(ReportList *reports, VFont *vfont, int how)
        return (ret_value);
 }
 
-int unpackSample(ReportList *reports, bSample *sample, int how)
+int unpackSound(ReportList *reports, bSound *sound, int how)
 {
        char localname[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX];
        char *newname;
        int ret_value = RET_ERROR;
-       PackedFile *pf;
-       
-       if (sample != NULL) {
-               strcpy(localname, sample->name);
+
+       if (sound != NULL) {
+               strcpy(localname, sound->name);
                BLI_splitdirstring(localname, fi);
-               sprintf(localname, "//samples/%s", fi);
-               
-               newname = unpackFile(reports, sample->name, localname, sample->packedfile, how);
+               sprintf(localname, "//sounds/%s", fi);
+
+               newname = unpackFile(reports, sound->name, localname, sound->packedfile, how);
                if (newname != NULL) {
-                       strcpy(sample->name, newname);
+                       strcpy(sound->name, newname);
                        MEM_freeN(newname);
 
-                       pf = sample->packedfile;
-                       // because samples and sounds can point to the
-                       // same packedfile we have to check them all
-                       sound_set_packedfile(sample, NULL);
-                       freePackedFile(pf);
+                       freePackedFile(sound->packedfile);
+                       sound->packedfile = 0;
+
+                       sound_load(NULL, sound);
 
                        ret_value = RET_OK;
                }
@@ -513,7 +519,7 @@ void unpackAll(Main *bmain, ReportList *reports, int how)
 {
        Image *ima;
        VFont *vf;
-       bSample *sample;
+       bSound *sound;
 
        for(ima=bmain->image.first; ima; ima=ima->id.next)
                if(ima->packedfile)
@@ -523,9 +529,8 @@ void unpackAll(Main *bmain, ReportList *reports, int how)
                if(vf->packedfile)
                        unpackVFont(reports, vf, how);
 
-       if(samples)
-               for(sample=samples->first; sample; sample=sample->id.next)
-                       if(sample->packedfile)
-                               unpackSample(reports, sample, how);
+       for(sound=bmain->sound.first; sound; sound=sound->id.next)
+               if(sound->packedfile)
+                       unpackSound(reports, sound, how);
 }