ReactOS 0.4.15-dev-7674-gc0b4db1
pendmoves.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS pending moves operations Information tool
4 * FILE: cmdutils/pendmoves/pendmoves.c
5 * PURPOSE: Query information from registry about pending moves
6 * PROGRAMMERS: Pierre Schweitzer <pierre@reactos.org>
7 */
8
9#include <windows.h>
10#include <tchar.h>
11#include <stdio.h>
12
13static
14TCHAR *
16{
17 DWORD LocalLen = *Len;
18
19 /* If there's a ! marking that existing file can be overwritten,
20 * drop it
21 */
22 if (LocalLen > 1)
23 {
24 if (Path[0] == _T('!'))
25 {
26 ++Path;
27 --LocalLen;
28 }
29 }
30
31 /* Remove namespace if prefixed */
32 if (LocalLen > 4)
33 {
34 if (Path[0] == _T('\\') && Path[1] == _T('?') &&
35 Path[2] == _T('?') && Path[3] == _T('\\'))
36 {
37 Path += 4;
38 LocalLen -= 4;
39 }
40 }
41
42 /* Return modified string + len */
43 *Len = LocalLen;
44 return Path;
45}
46
47static
50{
51 DWORD Chars, i, j, Count, SrcLen, TgtLen;
52 TCHAR * SrcFile, * Target, * Current;
53
54 /* Compute the amount of chars
55 * NULL char isn't relaible EOF (MULTI_SZ)
56 */
57 Chars = Len / sizeof(TCHAR);
58
59 i = 0;
60 Count = 0;
61 Current = Value;
62 /* Browse the whole string */
63 while (i < Chars)
64 {
65 /* Jump to the next NULL (end of source) */
66 for (j = i; j < Chars && Value[j] != 0; ++j);
67 /* Get len & clean path */
68 SrcLen = _tcslen(Current);
69 SrcFile = BeautifyPath(Current, &SrcLen);
70 /* Source file is null - likely the end of the MULTI_SZ, quit */
71 if (SrcLen == 0)
72 {
73 break;
74 }
75
76 /* Remember position, jump to the begin of the target */
77 i = j;
78 ++i;
79 /* Update position in MULTI_SZ */
80 Current = Value + i;
81
82 /* Jump to the next NULL (end of target) */
83 for (j = i; j < Chars && Value[j] != 0; ++j);
84 /* Get len & clean path */
85 TgtLen = _tcslen(Current);
86 Target = BeautifyPath(Current, &TgtLen);
87 /* Remember position, jump to the begin of the next source */
88 i = j;
89 ++i;
90 Current = Value + i;
91
92 /* Display source */
93 _ftprintf(stdout, _T("Source: %s\n"), SrcFile);
94 /* If is accessible? Warn if not */
96 {
97 _ftprintf(stdout, _T("\t *** Source file lookup error: %d\n"), GetLastError());
98 }
99 /* And display target - if empty, it's for deletion, mark as it */
100 _ftprintf(stdout, _T("Target: %s\n\n"), (_tcslen(Target) != 0 ? Target: _T("DELETE")));
101
102 /* Remember position and number of entries */
103 Current = Value + i;
104 ++Count;
105 }
106
107 return Count;
108}
109
110int
112_tmain(int argc, const TCHAR *argv[])
113{
114 HKEY hKey;
115 LONG Ret;
116 DWORD MaxLen, Len, Count, Type;
118 FILETIME LastModified;
119 TCHAR RegistryPath[] = _T("System\\CurrentControlSet\\Control\\Session Manager");
120
121 /* Open the SMSS registry key */
123 if (Ret != ERROR_SUCCESS)
124 {
125 _ftprintf(stderr, _T("Failed opening the registry key '%s' (%lx)\n"), RegistryPath, Ret);
126 return 1;
127 }
128
129 /* Get last modified date + buffer length we need to allocate */
130 Ret = RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &MaxLen, NULL, &LastModified);
131 if (Ret != ERROR_SUCCESS)
132 {
134 _ftprintf(stderr, _T("Failed querying information for '%s' (%lx)\n"), RegistryPath, Ret);
135 return 1;
136 }
137
138 /* No value, so no operations */
139 if (MaxLen == 0)
140 {
142 _ftprintf(stdout, _T("No pending file rename operations registered.\n\n"));
143 return 0;
144 }
145
146 /* Allocate memory */
147 Buffer = HeapAlloc(GetProcessHeap(), 0, MaxLen);
148 if (Buffer == NULL)
149 {
151 _ftprintf(stderr, _T("Failed allocating %d bytes\n"), MaxLen);
152 return 1;
153 }
154
155 /* Start with PendingFileRenameOperations */
156 Count = 0;
157 Len = MaxLen;
158 Ret = RegQueryValueEx(hKey, _T("PendingFileRenameOperations"), NULL, &Type, Buffer, &Len);
159 if (Ret == ERROR_SUCCESS && Type == REG_MULTI_SZ)
160 {
162 }
163
164 /* Continue with PendingFileRenameOperations2 - used if PendingFileRenameOperations is too big */
165 Len = MaxLen;
166 Ret = RegQueryValueEx(hKey, _T("PendingFileRenameOperations2"), NULL, &Type, Buffer, &Len);
167 if (Ret == ERROR_SUCCESS && Type == REG_MULTI_SZ)
168 {
170 }
171
172 /* Release everything */
175
176 /* If we found entries, display modification date */
177 if (Count != 0)
178 {
179 FILETIME LocalTime;
180 SYSTEMTIME SysTime;
181
182 /* Convert our UTC time to local time, and then to system time to allow easy display */
183 if (FileTimeToLocalFileTime(&LastModified, &LocalTime) && FileTimeToSystemTime(&LocalTime, &SysTime))
184 {
185 _ftprintf(stdout, _T("Time of last update to pending moves key: %02d/%02d/%04d %02d:%02d\n\n"),
186 SysTime.wDay, SysTime.wMonth, SysTime.wYear, SysTime.wHour, SysTime.wMinute);
187 }
188 }
189 /* No operations found */
190 else
191 {
192 _ftprintf(stdout, _T("No pending file rename operations registered.\n\n"));
193 }
194
195 return 0;
196}
PRTL_UNICODE_STRING_BUFFER Path
static int argc
Definition: ServiceArgs.c:12
Type
Definition: Type.h:7
#define __cdecl
Definition: accygwin.h:79
#define RegCloseKey(hKey)
Definition: registry.h:49
Definition: bufpool.h:45
#define Len
Definition: deflate.h:82
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:188
BOOL WINAPI FileTimeToLocalFileTime(IN CONST FILETIME *lpFileTime, OUT LPFILETIME lpLocalFileTime)
Definition: time.c:221
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define stdout
Definition: stdio.h:99
#define stderr
Definition: stdio.h:100
#define _tmain
Definition: tchar.h:497
#define _ftprintf
Definition: tchar.h:518
#define argv
Definition: mplay32.c:18
int Count
Definition: noreturn.cpp:7
#define REG_MULTI_SZ
Definition: nt_native.h:1501
long LONG
Definition: pedump.c:60
static TCHAR * BeautifyPath(TCHAR *Path, DWORD *Len)
Definition: pendmoves.c:15
static DWORD DisplayPendingOps(TCHAR *Value, DWORD Len)
Definition: pendmoves.c:49
WORD wYear
Definition: winbase.h:905
WORD wMonth
Definition: winbase.h:906
WORD wHour
Definition: winbase.h:909
WORD wMinute
Definition: winbase.h:910
WORD wDay
Definition: winbase.h:908
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
#define _T(x)
Definition: vfdio.h:22
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define GetFileAttributes
Definition: winbase.h:3750
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegQueryValueEx
Definition: winreg.h:524
#define RegOpenKey
Definition: winreg.h:519
#define RegQueryInfoKey
Definition: winreg.h:521
char TCHAR
Definition: xmlstorage.h:189
#define _tcslen
Definition: xmlstorage.h:198