Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
multi_volume_p.c
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
3 #2023 X March 21 19:50 PM Brasília Time
4
5* *
6* Licensa de Copia (C) <2023> <Aurora Boreal> *
7* *
8* Este programa e software livre: voce pode redistribuir isto e/ou *
9* modificar isto sobre os termos do GNU Licensa Geral Pública como 25
10* publicado pela Fundacao de Software Livre, tanto a versão 3 da *
11* Licensa, ou (dependendo da sua opcao) qualquer versao posterior. *
12* *
13* Este programa e distribuido na esperanca que isto vai ser util, *
14* mas SEM QUALQUER GARANTIA; sem ate mesmo a implicada garantia de *
15* COMERCIALIZAcaO ou CABIMENTO PARA UM FIM PARTICULAR. Veja a *
16* Licensa Geral Publica para mais detalhes. *
17* *
18* Você deve ter recebido uma cópia da LICENSA GERAL PUBLICA e a GNU *
19* Licensa Publica Menor junto com este programa *
20* Se não, veja <http://www.gnu.org/licenses/>. *
21* *
22* Suporte: sourceforge.net github.com *
23* *
24* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
25
26* Pereira: arsoftware25@gmail.com ricardo@arsoftware.net.br *
27* xcx: arsoftware10@gmail.com charli@arsoftware.net.br *
28 Yasmin: yasmin@arsoftware.net.br *
29 pereira1001@users.sourceforge.net
30 */
31
32
33#include <windows.h>
34#include <stdint.h>
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38#include <time.h>
39#include <errno.h>
40#include <fcntl.h>
41#include <ctype.h>
42#include <math.h>
43#include <wctype.h>
44#include <wchar.h>
45#include <stdarg.h>
46#include <stddef.h>
47#include <setjmp.h>
48#include <locale.h>
49#include <signal.h>
50#include <limits.h>
51#include <float.h>
52#include <iso646.h>
53
54#undef NDEBUG
55#include <assert.h>
56
57#include <stdbool.h>
58
59#include <process.h>
60
61#ifndef uchar
62#define uchar unsigned char
63#endif
64
65#ifndef uint
66#define uint unsigned int
67#endif
68
69#ifndef ushort
70#define ushort unsigned short
71#endif
72
74//defines
75
76#define CHUNK_P (1 << 17)
77
78int64_t slice_in_bytes_p = 0;
79
81//functions declared
82
83char *
85
87
88int size_of_WCHAR_mem_r(char *in_string);
89
90//88888888888888888888888888888
101WCHAR *amanda_asciitowide_1_(char *pUTF8, WCHAR *ar_temp);
102/*
103{
104 static WCHAR ricardo_k[1024];
105
106 MultiByteToWideChar(CP_UTF8_no_charli, 0, (LPCSTR)pUTF8, -1, ricardo_k, 1024);
107 return ricardo_k;
108}
109*/
119__int64
120getfilesize_ar(char *infile_ar);
121/*
122{
123 __int64 ret;
124 FILE *myfile;
125
126 if ((myfile = _wfopen(amanda_asciitowide_1_(infile_ar), L"rb")) == NULL)
127 {
128 return 0;
129 }
130 ret = _fseeki64(myfile, 0, SEEK_END);
131 ret = _ftelli64(myfile);
132 fclose(myfile);
133 return ret;
134}
135*/
147char *
148strrstr(char *s1, char *s2);
149/*
150{
151 char *sc2, *psc1, *ps1;
152 if (*s2 == '\0')
153 {
154 return((char *)s1);
155 }
156 ps1 = s1 + strlen(s1);
157 while (ps1 != s1)
158 {
159 --ps1;
160 for (psc1 = ps1, sc2 = s2;;)
161 {
162 if (*(psc1++) != *(sc2++))
163 {
164 break;
165 }
166 else if (*sc2 == '\0')
167 {
168 return((char *)ps1);
169 }
170 }
171 }
172 return((char *)((void *)0));
173}
174*/
175
189int stripfilenameandpath(char *path, char *onlypath, char *onlyfilename);
190/*
191{
192 char*ptr;
193
194 ptr = strrstr(path, "\\");
195
196 if (ptr)
197 {
198 if (onlypath)
199 {
200 strcpy(onlypath, path),
201 onlypath[ptr - path] = 0;
202 }
203
204 if (onlyfilename)
205 {
206 strcpy(onlyfilename, &path[ptr - path + 1]);
207 }
208 }
209 else
210 {
211 if (onlypath)
212 {
213 strcpy(onlypath, "");
214 }
215 if (onlyfilename)
216 {
217 strcpy(onlyfilename, path);
218 }
219 }
220
221 return 0;
222}
223*/
224
225void __fastcall get_extension_p(char *filename_p, char *extension_p)
226{
227
228 char *ptr_p;
229 static char filename_copy_p[1027];
230 static char filename_copy_2_p[1027];
231
232 strcpy(filename_copy_2_p, filename_p);
233
234 ptr_p = filename_copy_2_p;
235
236 while (*ptr_p)
237 {
238 if ('/' == *ptr_p)
239 {
240 *ptr_p = '\\';
241 }
242 ptr_p++;
243 }
244
245 stripfilenameandpath(filename_copy_2_p, NULL, filename_copy_p);
246
247 ptr_p = strrstr(filename_copy_p, ".");
248
249 if (ptr_p)
250 {
251 strcpy(extension_p, ptr_p + 1);
252 }
253 else
254 {
255 extension_p[0] = 0;
256 }
257
258 return;
259}
260
261int __fastcall detect_multi_volume_p(char *filename_utf_8_p, char *adjusted_filename_in_temp_p)
262{
263 //int position_p ;
264 //char * pointer_char_p ;
265 FILE *my_input_file = NULL;
266 FILE *my_file_p = NULL;
267 char *ptr_p;
268 char *buf_p;
269 static char constructed_chunk_p[AMANDA__SIZE];
270 static char temp_folder_name_p[AMANDA__SIZE];
271 static char first_chunk_p[AMANDA__SIZE];
272 static char the_extension_p[AMANDA__SIZE];
273 char temp_p[300];
274 int i_p;
275 int counter_p;
276 int return_value_p = 0;
277 int len_p;
278 int check_write_p;
279 bool found_p = false;
280 bool did_p = false;
281 /*
282
283 vamos ver as extensoes primeiro...
284
285 */
286
287 buf_p = malloc(CHUNK_P);
288 adjusted_filename_in_temp_p[0] = 0;
289
290 if (0 == constructed_chunk_p[0] && 1 == constructed_chunk_p[0])
291 {
292 return 0;
293 }
294
295 get_extension_p(filename_utf_8_p, the_extension_p);
296
297 if (strlen(the_extension_p) && 3 == strlen(the_extension_p))
298 {
299 for (i_p = 1; i_p < 100; i_p++)
300 {
301
302 sprintf(temp_p, "%03d", i_p);
303
304 if (0 == strcmp(the_extension_p, temp_p))
305 {
306
307 found_p = true;
308 break;
309 }
310 }
311 }
312
313 if (found_p)
314 {
315 counter_p = 1;
316
317 if (-1 == counter_p)
318 {
319
320 return false;
321 }
322 retorno_p:;
323
324 strcpy(first_chunk_p, filename_utf_8_p);
325
326 ptr_p = strrstr(first_chunk_p, ".");
327
328 *ptr_p = 0;
329
330 if (0 == strlen(adjusted_filename_in_temp_p))
331 {
332
333 stripfilenameandpath(first_chunk_p, NULL, adjusted_filename_in_temp_p);
334
335 strcpy(temp_folder_name_p, ar_gettemppath_z());
336 //strcat(temp_folder_name_p, "\\");
337
338 if ('\\' != temp_folder_name_p[strlen(temp_folder_name_p) - 1])
339 {
340 strcat(temp_folder_name_p, "\\");
341 }
342
343 strcat(temp_folder_name_p, adjusted_filename_in_temp_p);
344 strcpy(adjusted_filename_in_temp_p, temp_folder_name_p);
345
346 pedro_dprintf(-1, "file in temp folder %s\n", adjusted_filename_in_temp_p);
347
348 //vai abrir o arquivo...
349
350 {
351 int r_temp = size_of_WCHAR_mem_r(adjusted_filename_in_temp_p);
352 WCHAR *ar_temp = (void *)malloc(r_temp);
353 WCHAR *ar_temp2 = (void *)malloc(r_temp);
354
355 my_file_p = _wfopen(permissive_name_m_(amanda_asciitowide_1_(adjusted_filename_in_temp_p, ar_temp), ar_temp2), L"wb");
356
357 free(ar_temp);
358 free(ar_temp2);
359 }
360 if (!my_file_p)
361 {
362
363 return_value_p = 5112;
364 strcpy(error_message_k, "Cannot open temp file to write");
365 goto saida_p;
366 }
367 }
368
369 pedro_dprintf(-1, "ajustado %s\n", first_chunk_p);
370
371 sprintf(first_chunk_p + strlen(first_chunk_p), ".%03d", counter_p);
372
373 pedro_dprintf(-1, "final %s\n", first_chunk_p);
374 {
375 int r_temp = size_of_WCHAR_mem_r(first_chunk_p);
376 WCHAR *ar_temp = (void *)malloc(r_temp);
377 WCHAR *ar_temp2 = (void *)malloc(r_temp);
378
379 my_input_file = _wfopen(permissive_name_m_(amanda_asciitowide_1_(first_chunk_p, ar_temp), ar_temp2), L"rb");
380
381 free(ar_temp);
382 free(ar_temp2);
383 }
384 if (!my_input_file)
385 {
386 if (false == did_p)
387 {
388
389 return_value_p = 5113;
390 pedro_dprintf(-1, "Cannot find first file to join\n");
391 strcpy(error_message_k, "Cannot find first file to join");
392
393 fclose(my_file_p);
394 my_file_p = NULL;
395 {
396 int r_temp = size_of_WCHAR_mem_r(adjusted_filename_in_temp_p);
397 WCHAR *ar_temp = (void *)malloc(r_temp);
398 WCHAR *ar_temp2 = (void *)malloc(r_temp);
399
400 _wunlink(permissive_name_m_(amanda_asciitowide_1_(adjusted_filename_in_temp_p, ar_temp), ar_temp2));
401
402 free(ar_temp);
403 free(ar_temp2);
404 }
405 //goto saida_p;
406 }
407 goto saida_p;
408 }
409 did_p = true;
410
411 again_p:;
412
413 len_p = fread(buf_p, 1, CHUNK_P, my_input_file);
414
415 check_write_p = fwrite(buf_p, 1, len_p, my_file_p);
416
417 if (check_write_p != len_p)
418 {
419 return_value_p = 5114;
420 pedro_dprintf(-1, "Cannot write to temporary file\n");
421 strcpy(error_message_k, "Cannot write to temporary file");
422 goto saida_p;
423 }
424
425 if (len_p)
426 {
427 goto again_p;
428 }
429
430 fclose(my_input_file);
431 my_input_file = NULL;
432 counter_p++;
433 goto retorno_p;
434 }
435
436 pedro_dprintf(-1, "� multi-volume %d\n", (int)found_p);
437
438 if (-1 == return_value_p)
439 {
440 goto saida_p;
441 }
442
443saida_p:;
444
445 free(buf_p);
446 if (my_file_p)
447 {
448 fclose(my_file_p);
449 }
450 if (my_input_file)
451 {
452 fclose(my_input_file);
453 }
454 if (0 == return_value_p && did_p)
455 {
456
457 return 1;
458 }
459
460 return return_value_p; //maybe an error
461}
462
463int __fastcall split_in_multiple_volumes_p(char *filename_utf_8_p)
464{
465
466 int len_p;
467 int return_value_p = 0;
468 int ret_arp_;
469 int counter_p = 0;
470 int check_write_p;
471 int64_t remaining_p;
472 int64_t remaining_slice_p;
473 FILE *input__p = NULL;
474 FILE *output_p = NULL;
475 char out_file_p[AMANDA__SIZE];
476 char *temp_data_p = NULL;
477 /*
478 {
479 char extension_p[300] = {0};
480 get_extension_p(filename_utf_8_p, extension_p);
481
482 pedro_dprintf(-1, "pegou extensao .%s.\n", extension_p);
483 }
484*/
485 int64_t original_size_p = getfilesize_ar(filename_utf_8_p);
486
487 if (NULL == output_p && NULL != output_p &&
488 remaining_p && ret_arp_) //to make compiler happy
489 {
490 return -27;
491 }
492 pedro_dprintf(-1, "dentro, sizes %lld %lld\n",
494 original_size_p);
495
496 if (0 != slice_in_bytes_p && 0 != original_size_p)
497 {
498 if (original_size_p > slice_in_bytes_p)
499 {
500 remaining_p = original_size_p;
501
502 temp_data_p = malloc(CHUNK_P);
503 {
504 int r_temp = size_of_WCHAR_mem_r(filename_utf_8_p);
505 WCHAR *ar_temp = (void *)malloc(r_temp);
506 WCHAR *ar_temp2 = (void *)malloc(r_temp);
507
508 input__p = _wfopen(permissive_name_m_(amanda_asciitowide_1_(filename_utf_8_p, ar_temp), ar_temp2), L"rb");
509
510 free(ar_temp);
511 free(ar_temp2);
512 }
513
514 if (!input__p)
515 {
516
517 return_value_p = 5101;
518 strcpy(error_message_k, "Cannot open output file to split");
519 goto saida_p;
520 }
521
522 while (1)
523 {
524 counter_p++;
525
526 strcpy(out_file_p, filename_utf_8_p);
527
528 sprintf(out_file_p + strlen(out_file_p),
529 ".%03d",
530 counter_p + 1);
531 {
532 int r_temp = size_of_WCHAR_mem_r(out_file_p);
533 WCHAR *ar_temp = (void *)malloc(r_temp);
534 WCHAR *ar_temp2 = (void *)malloc(r_temp);
535
536 _wunlink(permissive_name_m_v27(amanda_asciitowide_1_(out_file_p, ar_temp), ar_temp2));
537
538 free(ar_temp);
539 free(ar_temp2);
540 }
541 strcpy(out_file_p, filename_utf_8_p);
542
543 sprintf(out_file_p + strlen(out_file_p),
544 ".%03d",
545 counter_p);
546
547 pedro_dprintf(-1, "saiu %s\n", out_file_p);
548 {
549 int r_temp = size_of_WCHAR_mem_r(out_file_p);
550 WCHAR *ar_temp = (void *)malloc(r_temp);
551 WCHAR *ar_temp2 = (void *)malloc(r_temp);
552
553 output_p = _wfopen(permissive_name_m_(amanda_asciitowide_1_(out_file_p, ar_temp), ar_temp2), L"wb");
554
555 free(ar_temp);
556 free(ar_temp2);
557 }
558
559 if (output_p)
560 {
561 remaining_slice_p = slice_in_bytes_p;
562
563 more_data_p:;
564
565 len_p = fread(temp_data_p, 1, min(remaining_slice_p, CHUNK_P), input__p);
566
567 check_write_p = fwrite(temp_data_p, 1, len_p, output_p);
568
569 if (check_write_p != len_p)
570 {
571 return_value_p = 5102;
572 strcpy(error_message_k, "Cannot write to output file");
573 goto saida_p;
574 }
575
576 remaining_slice_p -= len_p;
577 remaining_p -= len_p;
578
579 if (0 == remaining_p)
580 {
581 pedro_dprintf(-1, "terminou split \n");
582 fclose(input__p);
583 input__p = NULL;
584 {
585 int r_temp = size_of_WCHAR_mem_r(filename_utf_8_p);
586 WCHAR *ar_temp = (void *)malloc(r_temp);
587 WCHAR *ar_temp2 = (void *)malloc(r_temp);
588
589 _wunlink(permissive_name_m_(amanda_asciitowide_1_(filename_utf_8_p, ar_temp), ar_temp2));
590
591 free(ar_temp);
592 free(ar_temp2);
593 }
594
595 goto saida_p;
596 }
597 if (0 != len_p)
598 {
599 goto more_data_p;
600 }
601
602 fclose(output_p);
603 output_p = NULL;
604 }
605 else
606 {
607 return_value_p = 5104;
608 strcpy(error_message_k, "Cannot open output file to write");
609 goto saida_p;
610 }
611 /*
612 if(10 == counter_p)
613 {
614 pedro_dprintf(-1, "limitado a dez chunks\n");
615 break;
616 }
617 */
618 }
619 }
620 }
621
622saida_p:;
623
624 if (input__p)
625 {
626 fclose(input__p);
627 }
628 if (output_p)
629 {
630 fclose(output_p);
631 }
632 if (temp_data_p)
633 {
634 free(temp_data_p);
635 }
636 return return_value_p;
637}
638
639int __stdcall split_compressed_file_p(int64_t slice_in_bytes_p_)
640{
641 slice_in_bytes_p = slice_in_bytes_p_;
642
643 if (0 > slice_in_bytes_p)
644 {
645
647 }
648
649 return 0;
650}
#define AMANDA__SIZE
Definition arp.h:149
wchar_t * permissive_name_m_(const wchar_t *wname, WCHAR *ar_temp)
Definition tar_1_33.c:279
void pedro_dprintf(int amanda_level, char *format,...)
Definition pedro.c:43
int stripfilenameandpath(char *path, char *onlypath, char *onlyfilename)
Definition extract_kkk.c:554
int __fastcall split_in_multiple_volumes_p(char *filename_utf_8_p)
Definition multi_volume_p.c:463
int __fastcall detect_multi_volume_p(char *filename_utf_8_p, char *adjusted_filename_in_temp_p)
Definition multi_volume_p.c:261
int size_of_WCHAR_mem_r(char *in_string)
Definition tar_1_33.c:694
#define CHUNK_P
Definition multi_volume_p.c:76
int __stdcall split_compressed_file_p(int64_t slice_in_bytes_p_)
Definition multi_volume_p.c:639
int64_t slice_in_bytes_p
Definition multi_volume_p.c:78
char * ar_gettemppath_z(void)
Definition tar_1_33.c:11455
char * strrstr(char *s1, char *s2)
Definition extract_kkk.c:469
void __fastcall get_extension_p(char *filename_p, char *extension_p)
Definition multi_volume_p.c:225
WCHAR * amanda_asciitowide_1_(char *pUTF8, WCHAR *ar_temp)
Definition tar_1_33.c:677
__int64 getfilesize_ar(char *infile_ar)
Definition tar_1_33.c:2432
#define min(a, b)
Definition compress42.c:304
wchar_t * permissive_name_m_v27(const wchar_t *wname, WCHAR *ar_temp)
copy of permissive_name_m_, because in some API calls you need to conversions to a wide path this is ...
Definition tar_1_33.c:376
int ret_arp_
Definition tar_1_33.c:592
char error_message_k[AMANDA__SIZE]
Definition tar_1_33.c:176
#define s1(x)
Definition Sha256.c:142
#define NULL
Definition getopt1.c:37