- change max threads from 8 to 64, need to keep an eye on stack memory use here.
[blender.git] / source / blender / blenkernel / intern / packedFile.c
index 590189fbd5d7e75b955be8ee9f064ff7db49abca..036cadebbe86a2d1341cc8b70bf0a8cd709b7fa4 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;
 }
@@ -169,6 +176,11 @@ PackedFile *newPackedFile(ReportList *reports, char *filename)
        char name[FILE_MAXDIR+FILE_MAXFILE];
        void *data;
        
+       /* render result has no filename and can be ignored
+        * any other files with no name can be ignored too */
+       if(filename[0]=='\0')
+               return NULL;
+
        //XXX waitcursor(1);
        
        // convert relative filenames to absolute filenames
@@ -181,7 +193,7 @@ PackedFile *newPackedFile(ReportList *reports, char *filename)
 
        file= open(name, O_BINARY|O_RDONLY);
        if (file <= 0) {
-               BKE_reportf(reports, RPT_ERROR, "Can't open file: %s", name);
+               BKE_reportf(reports, RPT_ERROR, "Can't open file: \"%s\"", name);
        } else {
                filelen = BLI_filesize(file);
 
@@ -208,8 +220,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 +230,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 +241,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;
@@ -456,28 +467,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;
                }
@@ -515,7 +524,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)
@@ -525,9 +534,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);
 }