summaryrefslogtreecommitdiff
path: root/plugins/WhoUsesMyFiles/src/list.cpp
blob: 25f1230b8f3b23d22aad7f255e0694210116cc0e (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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "stdafx.h"

PWumf new_wumf( DWORD dwID, 
				LPTSTR szUser, 
				LPTSTR szPath, 
				LPTSTR szComp, 
				LPTSTR szUNC, 
				DWORD dwSess, 
				DWORD dwPerm, 
				DWORD dwAttr)
{
	PWumf w = (PWumf)mir_calloc(sizeof(Wumf));
	if (!w)
		return NULL;

	w->szUser = mir_tstrdup(szUser);
	w->szPath = mir_tstrdup(szPath);
	w->szComp = mir_tstrdup(szComp);
	w->szUNC  = mir_tstrdup(szUNC);

	switch(dwPerm) {
		case PERM_FILE_READ: mir_tstrcpy(w->szPerm, _T("Read"));break;
		case PERM_FILE_WRITE: mir_tstrcpy(w->szPerm, _T("Write"));break;
		case PERM_FILE_CREATE: mir_tstrcpy(w->szPerm, _T("Create"));break;
		default: mir_tstrcpy(w->szPerm, _T("Execute"));
	}
	mir_sntprintf(w->szID, _countof(w->szID), _T("%i"), dwID);

	w->dwID = dwID;
	w->dwSess = dwSess;
	w->dwAttr = dwAttr;
	w->dwPerm = dwPerm;
	w->mark = FALSE;
	w->next = NULL;
	return w;	
}

BOOL del_wumf(PWumf w)
{
	if (!w) return FALSE;
	mir_free(w->szUser);
	mir_free(w->szPath);
	mir_free(w->szComp);
	mir_free(w->szUNC);
	mir_free(w);
	return TRUE;
}

BOOL add_cell(PWumf* l, PWumf w)
{
	if (!w || !l)return FALSE;
	if (!(*l))
		*l = w;
	else {
		PWumf p = *l;
		while(p->next) p = p->next;
		p->next = w;
	}
	w->next = NULL;
	return TRUE;
}

BOOL del_cell(PWumf *l, PWumf w)
{
	if (!l || !*l || !w)return FALSE;
	PWumf p = *l;
	if (w == *l)
		*l = p->next;
	else {
		while(p && p->next != w) p = p->next;
		if (!p) return FALSE;
		p->next = w->next;
	}
	return del_wumf(w);
}

BOOL cpy_cell(PWumf *l, PWumf w)
{
	PWumf w1 = new_wumf(w->dwID, w->szUser, w->szPath, w->szComp,w->szUNC, w->dwSess, w->dwPerm, w->dwAttr);
	if (!w1)
		return FALSE;
	w1->mark = w->mark;
	return add_cell(l, w1);
}

PWumf cpy_list(PWumf *l)
{
	PWumf w, p = NULL;

	if (!l || !*l) return NULL;
	w = *l;
	while(w) {
		if (!cpy_cell(&p, w))return NULL;
		w = w->next;
	}
	return p;
}

PWumf fnd_cell(PWumf *l, DWORD dwID)
{
	if (!l || !*l)return NULL;
	PWumf w = *l;
	while(w && w->dwID != dwID) w = w->next;
	return w;
}

BOOL del_all(PWumf *l)
{
	if (!l || !*l) return FALSE;
	PWumf w = *l;
	while(w) {
		PWumf p = w->next;
		if (!del_cell(l, w)) 
			return FALSE;

		w = p;
	}
	*l = NULL;
	return TRUE;
}

BOOL del_marked(PWumf *l)
{
	PWumf w, p;
	if (!l)return FALSE;
	w = *l;
	while(w) {
		p = w->next;
		if (w->mark)
			if (!del_cell(l, w))
				return FALSE;

		w = p;
	}
	return TRUE;
}

void mark_all(PWumf *l, BOOL mark)
{
	PWumf w = *l;
	while(w) {
		w->mark = mark;
		w = w->next;
	}
}