-
Notifications
You must be signed in to change notification settings - Fork 1
/
uninstall.c
72 lines (61 loc) · 1.73 KB
/
uninstall.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
#include "uninstall.h"
#include "desktopfiles.h"
#include "apps.h"
#include "config.h"
int UninstallDir(TAction *Act, const char *Dir)
{
char *Tempstr=NULL;
const char *p_Path, *p_Base;
glob_t Glob;
struct stat Stat;
int i;
FileSystemUnMount(Dir, "");
Tempstr=QuoteCharsInStr(Tempstr, Dir, "[]?*");
Tempstr=CatStr(Tempstr, "/*");
glob(Tempstr, GLOB_PERIOD, 0, &Glob);
for (i=0; i < Glob.gl_pathc; i++)
{
p_Path=Glob.gl_pathv[i];
p_Base=GetBasename(p_Path);
if ((strcmp(p_Base, ".") !=0) && (strcmp(p_Base, "..") !=0) )
{
lstat(p_Path, &Stat);
if (S_ISDIR(Stat.st_mode))
{
UninstallDir(Act, p_Path);
}
else
{
unlink(p_Path);
if (Config->Flags & FLAG_DEBUG) printf("Deleted file: [%s]\n", p_Path);
}
}
}
if (rmdir(Dir)==0)
{
if (Config->Flags & FLAG_DEBUG) printf("Deleted directory: [%s]\n",Dir);
Destroy(Tempstr);
return(TRUE);
}
Tempstr=FormatStr(Tempstr, "ERROR: Can't delete directory [%s]: ", Dir);
perror(Tempstr);
Destroy(Tempstr);
return(FALSE);
}
void UnInstallApp(TAction *Act)
{
char *Tempstr=NULL;
if (Act->Flags & FLAG_DLC)
{
TerminalPutStr("~rERROR: DLC items cannot be uninstalled~0\n", NULL);
return;
}
printf("Uninstall: %s\n", Act->Name);
//We don't need this path, but this function also sets the 'prefix' var,
//which we do need for this operation
Tempstr=AppFormatPath(Tempstr, Act);
Tempstr=CopyStr(Tempstr, GetVar(Act->Vars, "prefix"));
UninstallDir(Act, Tempstr);
DesktopFileDelete(Act);
Destroy(Tempstr);
}