[email protected] 8 years ago
parent
commit
a106ee505d

+ 26 - 3
oxygine/src/HttpRequestTask.cpp

@@ -118,11 +118,14 @@ namespace oxygine
 
     bool HttpRequestTask::_prerun()
     {
+        _progressDeltaDelayed = 0;
+        _progressDispatched = false;
         _suitableResponse = false;
         _receivedContentSize = 0;
         _expectedContentSize = 0;
         _responseCode = 0;
         _response.clear();
+        _writeFileError = false;
         if (_fhandle)
             file::close(_fhandle);
         _fhandle = 0;
@@ -161,9 +164,18 @@ namespace oxygine
 
     void HttpRequestTask::asyncProgress(int delta, int loaded, int total)
     {
+        if (_progressDispatched && loaded != total)//dispatch progress only once per frame
+        {
+            _progressDeltaDelayed += delta;
+            return;
+        }
+
+        _progressDispatched = true;
         sync([ = ]()
         {
-            dispatchProgress(delta, loaded, total);
+            _progressDispatched = false;
+            dispatchProgress(delta + _progressDeltaDelayed, loaded, total);
+            _progressDeltaDelayed = 0;
         });
     }
 
@@ -179,7 +191,10 @@ namespace oxygine
 
     void HttpRequestTask::_dispatchComplete()
     {
-        Event ev(_suitableResponse ? COMPLETE : ERROR);
+        unsigned int id = _suitableResponse ? COMPLETE : ERROR;
+        if (_writeFileError)
+            id = ERROR;
+        Event ev(id);
         dispatchEvent(&ev);
     }
 
@@ -209,8 +224,16 @@ namespace oxygine
         if (!_suitableResponse)
             return;
 
+
         if (_fhandle)
-            file::write(_fhandle, data, size);
+        {
+            unsigned int written = file::write(_fhandle, data, size);
+            if (written != size)
+            {
+                _writeFileError = true;
+                return;
+            }
+        }
         else
         {
             const char* p = (const char*)data;

+ 5 - 0
oxygine/src/HttpRequestTask.h

@@ -84,7 +84,12 @@ namespace oxygine
         std::string _url;
         std::string _fname;
         file::handle _fhandle;
+        bool _writeFileError;
         bool _cacheEnabled;
+
+        bool _progressDispatched;
+        unsigned int _progressDeltaDelayed;
+
         std::vector<unsigned char> _response;
         std::vector<unsigned char> _postData;
 

+ 7 - 7
oxygine/src/core/ZipFileSystem.cpp

@@ -64,8 +64,8 @@ namespace oxygine
                 entry.refs = 0;
                 entry.pos = pos;
                 entry.zp = zp;
-                
-                char *str = entry.name;
+
+                char* str = entry.name;
                 for (int i = 0; str[i]; i++)
                     str[i] = tolower(str[i]);
 
@@ -271,7 +271,7 @@ namespace oxygine
         file_entry* Zips::getEntryByName(const char* name)
         {
             char str[255];
-            char *p = str;
+            char* p = str;
             while (*name)
             {
                 *p = tolower(*name);
@@ -281,7 +281,7 @@ namespace oxygine
             *p = 0;
 
             files::iterator it = _files.find(str);
-            if (it != _files.end())            
+            if (it != _files.end())
                 return &it->second;
 
             return 0;
@@ -315,12 +315,12 @@ namespace oxygine
 
             void release()
             {
-                ZipFileSystem *zfs = static_cast<ZipFileSystem *>(_fs);
+                ZipFileSystem* zfs = static_cast<ZipFileSystem*>(_fs);
                 MutexAutoLock lock(zfs->_zips.getMutex());
                 _entry->refs--;
 
                 int r = unzCloseCurrentFile(_entry->zp);
-                OX_ASSERT(r == UNZ_OK);                
+                OX_ASSERT(r == UNZ_OK);
                 delete this;
             }
 
@@ -391,7 +391,7 @@ namespace oxygine
 
             ~fileHandleZipStreaming()
             {
-                ZipFileSystem *zfs = static_cast<ZipFileSystem *>(_fs);
+                ZipFileSystem* zfs = static_cast<ZipFileSystem*>(_fs);
                 MutexAutoLock lock(zfs->_zips.getMutex());
                 _entry->refs--;
             }

+ 1 - 1
oxygine/src/core/ZipFileSystem.h

@@ -36,7 +36,7 @@ namespace oxygine
             bool read(const file_entry* entry, file::buffer& bf);
             bool isExists(const char* name);
 
-            file_entry*         getEntryByName(const char* name);            
+            file_entry*         getEntryByName(const char* name);
             const char*         getZipFileName(int i) const { return _zps[i].name; }
             Mutex&              getMutex() { return _lock; }
 

+ 7 - 7
oxygine/src/core/file.cpp

@@ -206,23 +206,23 @@ namespace oxygine
             return t;
         }
 
-        void write(handle fh_, const void* data, unsigned int size)
+        unsigned int  write(handle fh_, const void* data, unsigned int size)
         {
             fileHandle* fh = (fileHandle*)fh_;
-            fh->write(data, size);
+            return fh->write(data, size);
         }
 
-        void write(const std::string& file, const buffer& data, error_policy ep)
+        unsigned int write(const std::string& file, const buffer& data, error_policy ep)
         {
-            write(file, data.getData(), data.getSize(), ep);
+            return write(file, data.getData(), data.getSize(), ep);
         }
 
-        void write(const std::string& file, const void* data, unsigned int size, error_policy ep)
+        unsigned int write(const std::string& file, const void* data, unsigned int size, error_policy ep)
         {
             autoClose ac(open(file, "wb", ep));
             if (!ac.getHandle())
-                return;
-            write(ac.getHandle(), data, size);
+                return 0;
+            return write(ac.getHandle(), data, size);
         }
 
         unsigned int size(handle fh_)

+ 3 - 3
oxygine/src/core/file.h

@@ -72,11 +72,11 @@ namespace oxygine
         unsigned int read(handle, buffer& dest);
 
         /**Writes bytes to file*/
-        void write(handle, const void* data, unsigned int size);
+        unsigned int write(handle, const void* data, unsigned int size);
 
         /**Writes bytes to file*/
-        void write(const std::string& file, const buffer& data, error_policy ep = ep_show_error);
-        void write(const std::string& file, const void* data, unsigned int size, error_policy ep = ep_show_error);
+        unsigned int write(const std::string& file, const buffer& data, error_policy ep = ep_show_error);
+        unsigned int write(const std::string& file, const void* data, unsigned int size, error_policy ep = ep_show_error);
 
         /**Is file exists?*/
         bool exists(const std::string& file);