Delo se nadaljuje.
This commit is contained in:
parent
d9d01c8d13
commit
e4711e98f0
@ -42,22 +42,37 @@ UINT MSITSCA_API EvaluateScheduledTasks(MSIHANDLE hInstall)
|
|||||||
|
|
||||||
UINT uiResult;
|
UINT uiResult;
|
||||||
BOOL bIsCoInitialized = SUCCEEDED(::CoInitialize(NULL));
|
BOOL bIsCoInitialized = SUCCEEDED(::CoInitialize(NULL));
|
||||||
CString sComponent;
|
CString sSequenceFilename, sComponent;
|
||||||
|
CStringW sDisplayName;
|
||||||
|
CFile fSequence;
|
||||||
PMSIHANDLE hDatabase, hViewST;
|
PMSIHANDLE hDatabase, hViewST;
|
||||||
|
|
||||||
assert(0); // Attach debugger here or press "Ignore"!
|
assert(0); // Attach debugger here or press "Ignore"!
|
||||||
|
|
||||||
hDatabase = ::MsiGetActiveDatabase(hInstall);
|
{
|
||||||
if (!hDatabase) {
|
// Prepare our own "TODO" script.
|
||||||
uiResult = ERROR_INVALID_HANDLE;
|
LPTSTR szBuffer = sSequenceFilename.GetBuffer(MAX_PATH);
|
||||||
|
assert(szBuffer);
|
||||||
|
::GetTempPath(MAX_PATH, szBuffer);
|
||||||
|
::GetTempFileName(szBuffer, _T("TS"), 0, szBuffer);
|
||||||
|
sSequenceFilename.ReleaseBuffer();
|
||||||
|
}
|
||||||
|
if (!fSequence.Open(sSequenceFilename, CFile::modeWrite | CFile::shareDenyWrite | CFile::modeCreate | CFile::osSequentialScan)) {
|
||||||
|
uiResult = ERROR_CREATE_FAILED;
|
||||||
goto error1;
|
goto error1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uiResult = ::MsiDatabaseOpenView(hDatabase, _T("SELECT Component_ FROM ScheduledTask"), &hViewST);
|
hDatabase = ::MsiGetActiveDatabase(hInstall);
|
||||||
if (uiResult != ERROR_SUCCESS) goto error1;
|
if (!hDatabase) {
|
||||||
|
uiResult = ERROR_INVALID_HANDLE;
|
||||||
|
goto error2;
|
||||||
|
}
|
||||||
|
|
||||||
|
uiResult = ::MsiDatabaseOpenView(hDatabase, _T("SELECT Component_, DisplayName FROM ScheduledTask"), &hViewST);
|
||||||
|
if (uiResult != ERROR_SUCCESS) goto error2;
|
||||||
|
|
||||||
uiResult = ::MsiViewExecute(hViewST, NULL);
|
uiResult = ::MsiViewExecute(hViewST, NULL);
|
||||||
if (uiResult != ERROR_SUCCESS) goto error1;
|
if (uiResult != ERROR_SUCCESS) goto error2;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
PMSIHANDLE hRecord;
|
PMSIHANDLE hRecord;
|
||||||
@ -68,19 +83,30 @@ UINT MSITSCA_API EvaluateScheduledTasks(MSIHANDLE hInstall)
|
|||||||
if (uiResult == ERROR_NO_MORE_ITEMS)
|
if (uiResult == ERROR_NO_MORE_ITEMS)
|
||||||
break;
|
break;
|
||||||
else if (uiResult != ERROR_SUCCESS)
|
else if (uiResult != ERROR_SUCCESS)
|
||||||
goto error1;
|
goto error2;
|
||||||
|
|
||||||
|
// Read Component ID.
|
||||||
uiResult = ::MsiRecordGetString(hRecord, 1, sComponent);
|
uiResult = ::MsiRecordGetString(hRecord, 1, sComponent);
|
||||||
if (uiResult != ERROR_SUCCESS) goto error1;
|
if (uiResult != ERROR_SUCCESS) goto error2;
|
||||||
|
|
||||||
|
// Get component state and save for deferred processing.
|
||||||
uiResult = ::MsiGetComponentState(hInstall, sComponent, &iInstalled, &iAction);
|
uiResult = ::MsiGetComponentState(hInstall, sComponent, &iInstalled, &iAction);
|
||||||
if (uiResult != ERROR_SUCCESS) goto error1;
|
if (uiResult != ERROR_SUCCESS) goto error2;
|
||||||
|
fSequence << iAction;
|
||||||
|
|
||||||
|
// Get task's display name and save for deferred processing.
|
||||||
|
uiResult = ::MsiRecordGetStringW(hRecord, 2, sDisplayName);
|
||||||
|
if (uiResult != ERROR_SUCCESS) goto error2;
|
||||||
|
fSequence << sDisplayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
verify(::MsiViewClose(hViewST) == ERROR_SUCCESS);
|
verify(::MsiViewClose(hViewST) == ERROR_SUCCESS);
|
||||||
uiResult = ERROR_SUCCESS;
|
uiResult = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
error2:
|
||||||
|
fSequence.Close();
|
||||||
error1:
|
error1:
|
||||||
|
if (uiResult != ERROR_SUCCESS) ::DeleteFile(sSequenceFilename);
|
||||||
if (bIsCoInitialized) ::CoUninitialize();
|
if (bIsCoInitialized) ::CoUninitialize();
|
||||||
return uiResult;
|
return uiResult;
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,9 @@ namespace MSITSCA {
|
|||||||
// Lokalni include
|
// Lokalni include
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <afx.h>
|
||||||
|
#include <atlstr.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <msiquery.h>
|
#include <msiquery.h>
|
||||||
|
|
||||||
|
|
||||||
@ -79,17 +82,18 @@ namespace MSITSCA {
|
|||||||
// Funkcije inline
|
// Funkcije inline
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline UINT MsiRecordGetString(MSIHANDLE hRecord, unsigned int iField, CString &sValue)
|
inline UINT MsiRecordGetStringA(MSIHANDLE hRecord, unsigned int iField, CStringA &sValue)
|
||||||
{
|
{
|
||||||
DWORD dwSize = 0;
|
DWORD dwSize = 0;
|
||||||
UINT uiResult;
|
UINT uiResult;
|
||||||
|
|
||||||
// Query the actual string length first.
|
// Query the actual string length first.
|
||||||
uiResult = ::MsiRecordGetString(hRecord, iField, _T(""), &dwSize);
|
uiResult = ::MsiRecordGetStringA(hRecord, iField, "", &dwSize);
|
||||||
if (uiResult == ERROR_MORE_DATA) {
|
if (uiResult == ERROR_MORE_DATA) {
|
||||||
// Prepare the buffer to read the string data into and read it.
|
// Prepare the buffer to read the string data into and read it.
|
||||||
LPTSTR szBuffer = sValue.GetBuffer(dwSize++);
|
LPSTR szBuffer = sValue.GetBuffer(dwSize++);
|
||||||
uiResult = ::MsiRecordGetString(hRecord, iField, szBuffer, &dwSize);
|
assert(szBuffer);
|
||||||
|
uiResult = ::MsiRecordGetStringA(hRecord, iField, szBuffer, &dwSize);
|
||||||
if (uiResult == ERROR_SUCCESS) {
|
if (uiResult == ERROR_SUCCESS) {
|
||||||
// Read succeeded.
|
// Read succeeded.
|
||||||
sValue.ReleaseBuffer(dwSize);
|
sValue.ReleaseBuffer(dwSize);
|
||||||
@ -109,6 +113,67 @@ inline UINT MsiRecordGetString(MSIHANDLE hRecord, unsigned int iField, CString &
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline UINT MsiRecordGetStringW(MSIHANDLE hRecord, unsigned int iField, CStringW &sValue)
|
||||||
|
{
|
||||||
|
DWORD dwSize = 0;
|
||||||
|
UINT uiResult;
|
||||||
|
|
||||||
|
// Query the actual string length first.
|
||||||
|
uiResult = ::MsiRecordGetStringW(hRecord, iField, L"", &dwSize);
|
||||||
|
if (uiResult == ERROR_MORE_DATA) {
|
||||||
|
// Prepare the buffer to read the string data into and read it.
|
||||||
|
LPWSTR szBuffer = sValue.GetBuffer(dwSize++);
|
||||||
|
assert(szBuffer);
|
||||||
|
uiResult = ::MsiRecordGetStringW(hRecord, iField, szBuffer, &dwSize);
|
||||||
|
if (uiResult == ERROR_SUCCESS) {
|
||||||
|
// Read succeeded.
|
||||||
|
sValue.ReleaseBuffer(dwSize);
|
||||||
|
return ERROR_SUCCESS;
|
||||||
|
} else {
|
||||||
|
// Read failed. Empty the string and return error code.
|
||||||
|
sValue.ReleaseBuffer(0);
|
||||||
|
return uiResult;
|
||||||
|
}
|
||||||
|
} else if (uiResult == ERROR_SUCCESS) {
|
||||||
|
// The string in database is empty.
|
||||||
|
sValue.Empty();
|
||||||
|
return ERROR_SUCCESS;
|
||||||
|
} else {
|
||||||
|
// Return error code.
|
||||||
|
return uiResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Operatorji inline
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
inline CFile& operator <<(CFile &f, int i)
|
||||||
|
{
|
||||||
|
f.Write(&i, sizeof(int));
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline CFile& operator <<(CFile &f, const CStringA &str)
|
||||||
|
{
|
||||||
|
int iLength = str.GetLength();
|
||||||
|
f.Write(&iLength, sizeof(int));
|
||||||
|
f.Write((LPCSTR)str, sizeof(CHAR) * iLength);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline CFile& operator <<(CFile &f, const CStringW &str)
|
||||||
|
{
|
||||||
|
int iLength = str.GetLength();
|
||||||
|
f.Write(&iLength, sizeof(int));
|
||||||
|
f.Write((LPCWSTR)str, sizeof(WCHAR) * iLength);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // !defined(RC_INVOKED) && !defined(MIDL_PASS)
|
#endif // !defined(RC_INVOKED) && !defined(MIDL_PASS)
|
||||||
|
|
||||||
#endif // __MSITSCA_H__
|
#endif // __MSITSCA_H__
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#define _ATL_NO_AUTOMATIC_NAMESPACE
|
#define _ATL_NO_AUTOMATIC_NAMESPACE
|
||||||
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // Some CString constructors will be explicit
|
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // Some CString constructors will be explicit
|
||||||
|
|
||||||
|
#include <afx.h>
|
||||||
#include <atlbase.h>
|
#include <atlbase.h>
|
||||||
#include <atlstr.h>
|
#include <atlstr.h>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user