forked from Open-Shell/Open-Shell-Menu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileHelper.cpp
More file actions
62 lines (57 loc) · 1.92 KB
/
FileHelper.cpp
File metadata and controls
62 lines (57 loc) · 1.92 KB
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
#include "stdafx.h"
#include "StringUtils.h"
bool CreateFakeFolder( const wchar_t *source, const wchar_t *fname )
{
// create directory
CreateDirectory(fname,NULL);
if (!SetFileAttributes(fname,FILE_ATTRIBUTE_READONLY))
return false;
// create shortcut
wchar_t path[_MAX_PATH];
Sprintf(path,_countof(path),L"%s\\target.lnk",fname);
{
CComPtr<IShellLink> pLink;
HRESULT hr=pLink.CoCreateInstance(CLSID_ShellLink);
if (FAILED(hr)) return false;
pLink->SetPath(source);
CComQIPtr<IPersistFile> pFile(pLink);
if (!pFile) return false;
hr=pFile->Save(path,TRUE);
if (FAILED(hr)) return false;
}
// create desktop.ini
Sprintf(path,_countof(path),L"%s\\desktop.ini",fname);
HANDLE f=CreateFile(path,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,NULL);
if (f==INVALID_HANDLE_VALUE) return false;
const char *desktopIni="[.ShellClassInfo]\r\nCLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}\r\nFlags=2\r\n";
DWORD q;
WriteFile(f,desktopIni,Strlen(desktopIni),&q,NULL);
CloseHandle(f);
return true;
}
void DeleteFakeFolder( const wchar_t *fname )
{
wchar_t path[_MAX_PATH];
Sprintf(path,_countof(path),L"%s\\target.lnk",fname);
BOOL res;
res=SetFileAttributes(path,GetFileAttributes(path)&~FILE_ATTRIBUTE_READONLY);
res=DeleteFile(path);
Sprintf(path,_countof(path),L"%s\\desktop.ini",fname);
res=SetFileAttributes(path,GetFileAttributes(path)&~FILE_ATTRIBUTE_READONLY);
res=DeleteFile(path);
res=SetFileAttributes(fname,GetFileAttributes(fname)&~FILE_ATTRIBUTE_READONLY);
res=RemoveDirectory(fname);
}
bool IsFakeFolder( const wchar_t *fname )
{
wchar_t path[_MAX_PATH];
Sprintf(path,_countof(path),L"%s\\target.lnk",fname);
if (GetFileAttributes(path)!=INVALID_FILE_ATTRIBUTES)
{
Sprintf(path,_countof(path),L"%s\\desktop.ini",fname);
DWORD attrib=GetFileAttributes(path);
if (attrib!=INVALID_FILE_ATTRIBUTES && (attrib&FILE_ATTRIBUTE_SYSTEM))
return true;
}
return false;
}