Subversion Repositories tpanel

Rev

Rev 21 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21 Rev 125
Line 16... Line 16...
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
17
 */
18
 
18
 
19
#include <iostream>
19
#include <iostream>
20
#include <fstream>
20
#include <fstream>
21
#if __GNUC__ < 9 && !defined(__ANDROID__)
-
 
-
 
21
 
22
   #if __cplusplus < 201703L
22
#if __cplusplus < 201402L
23
      #warning "Your C++ compiler seems to have no support for C++17 standard!"
23
#   error "This module requires at least C++ 14 standard!"
24
   #endif
-
 
25
   #include <experimental/filesystem>
-
 
26
   namespace fs = std::experimental::filesystem;
-
 
27
#else
24
#else
-
 
25
#   if __cplusplus < 201703L
-
 
26
#       include <experimental/filesystem>
-
 
27
        namespace fs = std::experimental::filesystem;
-
 
28
#       warning "Support for C++14 and experimental filesystem will be removed in a future version!"
-
 
29
#   else
28
   #include <filesystem>
30
#       include <filesystem>
29
#  ifdef __ANDROID__
31
#       ifdef __ANDROID__
30
   namespace fs = std::__fs::filesystem;
32
            namespace fs = std::__fs::filesystem;
31
#  else
33
#       else
32
   namespace fs = std::filesystem;
34
            namespace fs = std::filesystem;
-
 
35
#       endif
33
#  endif
36
#   endif
34
#endif
37
#endif
-
 
38
 
-
 
39
#include <assert.h>
-
 
40
 
35
#include "texpand.h"
41
#include "texpand.h"
36
#include "terror.h"
42
#include "terror.h"
37
#include <assert.h>
-
 
38
 
43
 
39
using namespace std;
44
using namespace std;
40
 
45
 
41
void TExpand::setFileName (const string &fn)
46
void TExpand::setFileName (const string &fn)
42
{
47
{
Line 88... Line 93...
88
	if (ret != Z_OK)
93
	if (ret != Z_OK)
89
	{
94
	{
90
		zerr(ret);
95
		zerr(ret);
91
		fclose(source);
96
		fclose(source);
92
		fclose(dest);
97
		fclose(dest);
93
		fs::remove(target);
98
        fs::remove(target);
94
		return ret;
99
		return ret;
95
	}
100
	}
96
 
101
 
97
	do
102
	do
98
	{
103
	{
Line 102... Line 107...
102
		{
107
		{
103
			(void)inflateEnd(&strm);
108
			(void)inflateEnd(&strm);
104
			MSG_ERROR("Error reading from file " << fname << "!");
109
			MSG_ERROR("Error reading from file " << fname << "!");
105
			fclose(source);
110
			fclose(source);
106
			fclose(dest);
111
			fclose(dest);
107
			fs::remove(target);
112
            fs::remove(target);
108
			return Z_ERRNO;
113
			return Z_ERRNO;
109
		}
114
		}
110
 
115
 
111
		if (strm.avail_in == 0)
116
		if (strm.avail_in == 0)
112
			break;
117
			break;
Line 128... Line 133...
128
				case Z_DATA_ERROR:
133
				case Z_DATA_ERROR:
129
				case Z_MEM_ERROR:
134
				case Z_MEM_ERROR:
130
					(void)inflateEnd(&strm);
135
					(void)inflateEnd(&strm);
131
					fclose(source);
136
					fclose(source);
132
					fclose(dest);
137
					fclose(dest);
133
					fs::remove(target);
138
                    fs::remove(target);
134
					zerr(ret);
139
					zerr(ret);
135
					return ret;
140
					return ret;
136
			}
141
			}
137
 
142
 
138
			have = CHUNK - strm.avail_out;
143
			have = CHUNK - strm.avail_out;
Line 141... Line 146...
141
			{
146
			{
142
				(void)inflateEnd(&strm);
147
				(void)inflateEnd(&strm);
143
				MSG_ERROR("Error on writing to file " << target << "!");
148
				MSG_ERROR("Error on writing to file " << target << "!");
144
				fclose(source);
149
				fclose(source);
145
				fclose(dest);
150
				fclose(dest);
146
				fs::remove(target);
151
                fs::remove(target);
147
				return Z_ERRNO;
152
				return Z_ERRNO;
148
			}
153
			}
149
		}
154
		}
150
		while (strm.avail_out == 0);
155
		while (strm.avail_out == 0);
151
		// done when inflate() says it's done
156
		// done when inflate() says it's done
Line 153... Line 158...
153
	while (ret != Z_STREAM_END);
158
	while (ret != Z_STREAM_END);
154
	// clean up and return
159
	// clean up and return
155
	(void)inflateEnd(&strm);
160
	(void)inflateEnd(&strm);
156
	fclose(source);
161
	fclose(source);
157
	fclose(dest);
162
	fclose(dest);
158
	fs::remove(fname);
163
    fs::remove(fname);
159
	fs::rename(target, fname);
164
    fs::rename(target, fname);
160
	return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
165
	return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
161
}
166
}
162
 
167
 
163
void TExpand::zerr(int ret)
168
void TExpand::zerr(int ret)
164
{
169
{