-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkpar.c
79 lines (76 loc) · 1.8 KB
/
checkpar.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*\
|*| Parity Archive - A way to restore missing files in a set.
|*|
|*| Copyright (C) 2001 Willem Monsuwe ([email protected])
|*|
|*| File format by Stefan Wehlus -
|*| initial idea by Tobias Rieper, further suggestions by Kilroy Balore
|*|
|*| Check PAR files and restore missing files.
\*/
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <string.h>
#include "util.h"
#include "backend.h"
#include "rwpar.h"
#include "checkpar.h"
#include "fileops.h"
/*\
|*| Check the data files in a PXX file, and maybe restore missing files
\*/
int
check_par(par_t *par)
{
int m;
pfile_t *p;
u16 *str;
sub_t *sub = 0;
/*\ Look for all the data files \*/
for (m = 0, p = par->files; p; p = p->next) {
if (!find_file(p, 1) && USE_FILE(p))
m++;
}
if (cmd.smart)
sub = find_best_sub(par->files, 2);
if (cmd.fix) {
for (p = par->files; p; p = p->next) {
if (!find_file(p, 0))
continue;
str = do_sub(p->filename, sub);
if (!unicode_cmp(str, p->match->filename))
continue;
rename_away(p->match->filename, str);
}
}
if (m == 0) {
fprintf(stderr, "All files found\n");
free_sub(sub);
return 0;
}
if ((cmd.action != ACTION_MIX) && (find_volumes(par, m) < m)) {
fprintf(stderr, "\nToo many missing files:\n");
for (p = par->files; p; p = p->next) {
if (!p->match && USE_FILE(p))
fprintf(stderr, " %s\n", basename(p->filename));
}
free_sub(sub);
return -1;
}
if (cmd.action != ACTION_CHECK) {
fprintf(stderr, "\nRestoring:\n");
m = restore_files(par->files, par->volumes, sub);
free_sub(sub);
return m;
}
fprintf(stderr, "\nRestorable:\n");
for (p = par->files; p; p = p->next) {
if ((!p->match) && USE_FILE(p))
fprintf(stderr, " %-40s - can be restored\n",
basename(do_sub(p->filename, sub)));
}
free_sub(sub);
return 1;
}