| 71 HINSTANCE winpidgin_dll_hinstance(void) { |
70 HINSTANCE winpidgin_dll_hinstance(void) { |
| 72 return dll_hInstance; |
71 return dll_hInstance; |
| 73 } |
72 } |
| 74 |
73 |
| 75 int winpidgin_gz_decompress(const char* in, const char* out) { |
74 int winpidgin_gz_decompress(const char* in, const char* out) { |
| 76 gzFile fin; |
75 GFile *fin; |
| 77 FILE *fout; |
76 GFile *fout; |
| 78 char buf[1024]; |
77 GInputStream *input; |
| 79 int ret; |
78 GOutputStream *output; |
| 80 |
79 GOutputStream *conv_out; |
| 81 if((fin = gzopen(in, "rb"))) { |
80 GZlibDecompressor *decompressor; |
| 82 if(!(fout = g_fopen(out, "wb"))) { |
81 gssize size; |
| 83 purple_debug_error("winpidgin_gz_decompress", "Error opening file: %s\n", out); |
82 GError *error = NULL; |
| 84 gzclose(fin); |
83 |
| 85 return 0; |
84 fin = g_file_new_for_path(in); |
| 86 } |
85 input = G_INPUT_STREAM(g_file_read(fin, NULL, &error)); |
| 87 } |
86 g_object_unref(fin); |
| 88 else { |
87 |
| 89 purple_debug_error("winpidgin_gz_decompress", "gzopen failed to open: %s\n", in); |
88 if (input == NULL) { |
| |
89 purple_debug_error("winpidgin_gz_decompress", |
| |
90 "Failed to open: %s: %s\n", |
| |
91 in, error->message); |
| |
92 g_clear_error(&error); |
| 90 return 0; |
93 return 0; |
| 91 } |
94 } |
| 92 |
95 |
| 93 while((ret = gzread(fin, buf, 1024))) { |
96 fout = g_file_new_for_path(out); |
| 94 if ((int)fwrite(buf, 1, ret, fout) < ret) { |
97 output = G_OUTPUT_STREAM(g_file_replace(fout, NULL, FALSE, |
| 95 purple_debug_error("wpurple_gz_decompress", "Error writing %d bytes to file\n", ret); |
98 G_FILE_CREATE_NONE, NULL, &error)); |
| 96 gzclose(fin); |
99 g_object_unref(fout); |
| 97 fclose(fout); |
100 |
| 98 return 0; |
101 if (output == NULL) { |
| 99 } |
102 purple_debug_error("winpidgin_gz_decompress", |
| 100 } |
103 "Error opening file: %s: %s\n", |
| 101 fclose(fout); |
104 out, error->message); |
| 102 gzclose(fin); |
105 g_clear_error(&error); |
| 103 |
106 g_object_unref(input); |
| 104 if(ret < 0) { |
107 return 0; |
| 105 purple_debug_error("winpidgin_gz_decompress", "gzread failed while reading: %s\n", in); |
108 } |
| |
109 |
| |
110 decompressor = g_zlib_decompressor_new(G_ZLIB_COMPRESSOR_FORMAT_GZIP); |
| |
111 conv_out = g_converter_output_stream_new(output, |
| |
112 G_CONVERTER(decompressor)); |
| |
113 g_object_unref(decompressor); |
| |
114 g_object_unref(output); |
| |
115 |
| |
116 size = g_output_stream_splice(conv_out, input, |
| |
117 G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | |
| |
118 G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, NULL, &error); |
| |
119 |
| |
120 g_object_unref(input); |
| |
121 g_object_unref(conv_out); |
| |
122 |
| |
123 if (size < 0) { |
| |
124 purple_debug_error("wpurple_gz_decompress", |
| |
125 "Error writing to file: %s\n", |
| |
126 error->message); |
| |
127 g_clear_error(&error); |
| 106 return 0; |
128 return 0; |
| 107 } |
129 } |
| 108 |
130 |
| 109 return 1; |
131 return 1; |
| 110 } |
132 } |