blob: 1213f89d1e89ce1b0e078abe98e7d91bcf43031a (
plain)
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
|
/*
* visibility.c: Visibility classes for duplicates plugin.
*
* See the README file for copyright information and how to reach the author.
*
* $Id$
*/
#include "visibility.h"
// --- cVisibility -----------------------------------------------------------
cVisibility::cVisibility(const char *fileName) {
hiddenFileName = AddDirectory(fileName, "duplicates.hidden");
visibility = UNKNOWN;
}
cVisibility::cVisibility(const cVisibility &Visibility) :
hiddenFileName(Visibility.hiddenFileName),
visibility(Visibility.visibility) {}
eVisibility cVisibility::Get(void) {
return visibility;
}
void cVisibility::Set(bool visible) {
visibility = visible ? VISIBLE : HIDDEN;
}
eVisibility cVisibility::Read(void) {
if (visibility == UNKNOWN) {
visibility = access(hiddenFileName, F_OK) == 0 ? HIDDEN : VISIBLE;
}
return visibility;
}
bool cVisibility::Write(bool visible) {
if (visible) {
if (remove(hiddenFileName) == 0) {
visibility = VISIBLE;
return true;
}
} else {
FILE *f = fopen(hiddenFileName, "w");
if (f) {
fclose(f);
visibility = HIDDEN;
return true;
}
}
return false;
}
|