mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Big honkin' merge from head. Sheesh!
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3617 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,13 +18,13 @@
|
||||
#include "stdafx.h"
|
||||
#include "CAlfrescoApp.h"
|
||||
#include "CAlfrescoAppDlg.h"
|
||||
#include "FileStatusDialog.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "util\String.h"
|
||||
#include "util\DataBuffer.h"
|
||||
#include "util\FileName.h"
|
||||
#include "util\Integer.h"
|
||||
|
||||
#include <shellapi.h>
|
||||
|
||||
@@ -82,6 +82,7 @@ BOOL CCAlfrescoAppApp::InitInstance()
|
||||
// Get the path to the folder containing the application
|
||||
|
||||
String folderPath = appPath.substring(0, pos);
|
||||
String exeName = appPath.substring(pos + 1);
|
||||
|
||||
// Create the Alfresco interface
|
||||
|
||||
@@ -90,27 +91,69 @@ BOOL CCAlfrescoAppApp::InitInstance()
|
||||
|
||||
try {
|
||||
|
||||
// If there are no file paths on the command line then display a status page for the files
|
||||
// in the Alfresco folder
|
||||
// Get the action information
|
||||
|
||||
if ( __argc == 1) {
|
||||
AlfrescoActionInfo actionInfo = alfresco.getActionInformation(exeName);
|
||||
|
||||
// Display status for the files in the Alfresco folder
|
||||
// Check if the action should be confirmed
|
||||
|
||||
doFolderStatus( alfresco);
|
||||
if ( actionInfo.hasPreProcessAction(PreConfirmAction)) {
|
||||
|
||||
// Get the confirmation message
|
||||
|
||||
String confirmMsg = actionInfo.getConfirmationMessage();
|
||||
if ( confirmMsg.length() == 0)
|
||||
confirmMsg = L"Run action ?";
|
||||
|
||||
// Display a confirmation dialog
|
||||
|
||||
if ( AfxMessageBox( confirmMsg, MB_OKCANCEL | MB_ICONQUESTION) == IDCANCEL)
|
||||
return FALSE;
|
||||
}
|
||||
else {
|
||||
|
||||
// Build a list of the file names
|
||||
// Check if the action supports multiple paths, if not then call the action once for each supplied path
|
||||
|
||||
StringList fileList;
|
||||
if ( actionInfo.hasAttribute(AttrMultiplePaths)) {
|
||||
|
||||
// Build a list of paths from the command line arguments
|
||||
|
||||
StringList pathList;
|
||||
|
||||
for ( int i = 1; i < __argc; i++)
|
||||
fileList.addString( String(__wargv[i]));
|
||||
pathList.addString( String(__wargv[i]));
|
||||
|
||||
// Process the file list and check in or out each file
|
||||
// Run the action
|
||||
|
||||
doCheckInOut( alfresco, fileList);
|
||||
runAction( alfresco, pathList, actionInfo);
|
||||
}
|
||||
|
||||
// Check if the action supports file/folder targets
|
||||
|
||||
else if ( actionInfo.hasAttribute( AttrAnyFilesFolders) == true) {
|
||||
|
||||
// Pass one path at a time to the action
|
||||
|
||||
for ( int i = 1; i < __argc; i++) {
|
||||
|
||||
// Create a path list with a single path
|
||||
|
||||
StringList pathList;
|
||||
pathList.addString( String(__wargv[i]));
|
||||
|
||||
// Run the action
|
||||
|
||||
runAction( alfresco, pathList, actionInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// Action does not use targets, just run the action
|
||||
|
||||
else if ( actionInfo.allowsNoParameters()) {
|
||||
|
||||
// Run the action
|
||||
|
||||
StringList emptyList;
|
||||
runAction( alfresco, emptyList, actionInfo);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@@ -124,128 +167,36 @@ BOOL CCAlfrescoAppApp::InitInstance()
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Run the main dialog
|
||||
/**
|
||||
CCAlfrescoAppDlg dlg;
|
||||
m_pMainWnd = &dlg;
|
||||
INT_PTR nResponse = dlg.DoModal();
|
||||
if (nResponse == IDOK)
|
||||
{
|
||||
// TODO: Place code here to handle when the dialog is
|
||||
// dismissed with OK
|
||||
}
|
||||
else if (nResponse == IDCANCEL)
|
||||
{
|
||||
// TODO: Place code here to handle when the dialog is
|
||||
// dismissed with Cancel
|
||||
}
|
||||
**/
|
||||
// Exit the application
|
||||
|
||||
// Since the dialog has been closed, return FALSE so that we exit the
|
||||
// application, rather than start the application's message pump.
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display file status of the files in the target Alfresco folder
|
||||
*
|
||||
* @param AlfrescoInterface& alfresco
|
||||
* @param const wchar_t* fileSpec
|
||||
* @return bool
|
||||
*/
|
||||
bool CCAlfrescoAppApp::doFolderStatus( AlfrescoInterface& alfresco, const wchar_t* fileSpec) {
|
||||
|
||||
// Get the base UNC path
|
||||
|
||||
String uncPath = alfresco.getUNCPath();
|
||||
uncPath.append(PathSeperator);
|
||||
|
||||
// Search the Alfresco folder
|
||||
|
||||
WIN32_FIND_DATA findData;
|
||||
String searchPath = uncPath;
|
||||
searchPath.append( fileSpec);
|
||||
|
||||
bool sts = false;
|
||||
HANDLE fHandle = FindFirstFile( searchPath, &findData);
|
||||
AlfrescoFileInfoList fileList;
|
||||
|
||||
if ( fHandle != INVALID_HANDLE_VALUE) {
|
||||
|
||||
// Loop until all files have been returned
|
||||
|
||||
PTR_AlfrescoFileInfo pFileInfo;
|
||||
sts = true;
|
||||
|
||||
while ( fHandle != INVALID_HANDLE_VALUE) {
|
||||
|
||||
// Get the file name, ignore the '.' and '..' files
|
||||
|
||||
String fName = findData.cFileName;
|
||||
|
||||
if ( fName.equals(L".") || fName.equals(L"..")) {
|
||||
|
||||
// Get the next file/folder name in the search
|
||||
|
||||
if ( FindNextFile( fHandle, &findData) == 0)
|
||||
fHandle = INVALID_HANDLE_VALUE;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get the file information for the current file folder
|
||||
|
||||
pFileInfo = alfresco.getFileInformation( findData.cFileName);
|
||||
|
||||
if ( pFileInfo.get() != NULL) {
|
||||
|
||||
// Add the file to the list
|
||||
|
||||
fileList.addInfo( pFileInfo);
|
||||
}
|
||||
|
||||
// Get the next file/folder name in the search
|
||||
|
||||
if ( FindNextFile( fHandle, &findData) == 0)
|
||||
fHandle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
// Display the file status dialog if there are files to display
|
||||
|
||||
if ( fileList.size() > 0) {
|
||||
|
||||
// Display the file status dialog
|
||||
|
||||
CFileStatusDialog dlg( fileList);
|
||||
dlg.DoModal();
|
||||
}
|
||||
else {
|
||||
CString msg;
|
||||
msg.FormatMessage( L"No files found in %1", uncPath.data());
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONINFORMATION);
|
||||
}
|
||||
|
||||
// Return status
|
||||
|
||||
return sts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the list of files and check in or out each file
|
||||
* Process the command line arguments and build the parameter list for the desktop action
|
||||
*
|
||||
* @param alfresco AlfrescoInterface&
|
||||
* @param files StringList&
|
||||
* @param paths StringList&
|
||||
* @param actionInfo AlfrescoActionInfo&
|
||||
* @param params DesktopParams&
|
||||
* @return bool
|
||||
*/
|
||||
bool CCAlfrescoAppApp::doCheckInOut( AlfrescoInterface& alfresco, StringList& files) {
|
||||
bool CCAlfrescoAppApp::buildDesktopParameters( AlfrescoInterface& alfresco, StringList& paths, AlfrescoActionInfo& actionInfo,
|
||||
DesktopParams& params) {
|
||||
|
||||
// If there are no paths then just return a success
|
||||
|
||||
if ( paths.numberOfStrings() == 0)
|
||||
return true;
|
||||
|
||||
// Process the list of files and either check in the file if it is a working copy or check out
|
||||
// the file
|
||||
|
||||
for ( unsigned int i = 0; i < files.numberOfStrings(); i++) {
|
||||
for ( unsigned int i = 0; i < paths.numberOfStrings(); i++) {
|
||||
|
||||
// Get the current file name
|
||||
|
||||
String curFile = files.getStringAt( i);
|
||||
String curFile = paths.getStringAt( i);
|
||||
|
||||
// Check if the path is on an Alfresco mapped drive
|
||||
|
||||
@@ -259,171 +210,181 @@ bool CCAlfrescoAppApp::doCheckInOut( AlfrescoInterface& alfresco, StringList& fi
|
||||
curFile = uncPath;
|
||||
}
|
||||
|
||||
// Check that the path is to a file
|
||||
// Check if the path is to a file/folder, and whether it is a local path
|
||||
|
||||
bool copyFile = false;
|
||||
|
||||
DWORD attr = GetFileAttributes( curFile);
|
||||
if ( attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY) == 0) {
|
||||
|
||||
if ( attr != INVALID_FILE_ATTRIBUTES) {
|
||||
|
||||
// Check if the action supports the file/folder type
|
||||
|
||||
bool isDir = (attr & FILE_ATTRIBUTE_DIRECTORY) != 0 ? true : false;
|
||||
|
||||
if ( isDir && actionInfo.supportsFolders() == false) {
|
||||
AfxMessageBox(L"Action does not support folders", MB_OK | MB_ICONSTOP);
|
||||
return false;
|
||||
}
|
||||
else if ( actionInfo.supportsFiles() == false) {
|
||||
AfxMessageBox(L"Action does not support files", MB_OK | MB_ICONSTOP);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the file name from the path
|
||||
|
||||
StringList nameParts = FileName::splitPath( curFile);
|
||||
String curName = nameParts.getStringAt( 1);
|
||||
|
||||
// Get the Alfresco file status information
|
||||
|
||||
PTR_AlfrescoFileInfo pFileInfo = alfresco.getFileInformation( curName);
|
||||
|
||||
// If the path is to a file that is not on the Alfresco share the file will need to be copied,
|
||||
// after checking the status of a matching file in the Alfresco folder
|
||||
|
||||
if ( curFile.length() >= 3 && curFile.substring(1,3).equals( L":\\")) {
|
||||
|
||||
// Check if there is an existing file with the same name
|
||||
// Check if the action supports local files
|
||||
|
||||
if ( pFileInfo.get() != NULL) {
|
||||
if ( isDir == false && actionInfo.hasAttribute(AttrClientFiles) == false) {
|
||||
AfxMessageBox(L"Action does not support local files", MB_OK | MB_ICONSTOP);
|
||||
return false;
|
||||
}
|
||||
else if ( isDir == true && actionInfo.hasAttribute(AttrClientFolders) == false) {
|
||||
AfxMessageBox(L"Action does not support local folders", MB_OK | MB_ICONSTOP);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the file is a working copy
|
||||
// Check if there is an existing file in the Alfresco with the same name, check if the file is locked
|
||||
|
||||
PTR_AlfrescoFileInfo fInfo = alfresco.getFileInformation( curName);
|
||||
if ( fInfo.get() != NULL) {
|
||||
|
||||
if ( pFileInfo->isWorkingCopy()) {
|
||||
// There is an existing file in the Alfresco folder with the same name, check if it is locked
|
||||
|
||||
// Local file matches a working copy file in the Alfresco folder
|
||||
|
||||
CString msg;
|
||||
msg.FormatMessage( L"Found matching working copy for local file %1", curName.data());
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONINFORMATION);
|
||||
if ( fInfo->getLockType() != LockNone) {
|
||||
AfxMessageBox( L"Cannot copy file to Alfresco folder, destination file is locked", MB_OK | MB_ICONEXCLAMATION);
|
||||
return false;
|
||||
}
|
||||
else if ( pFileInfo->getLockType() != LockNone) {
|
||||
else if ( actionInfo.hasPreProcessAction(PreLocalToWorkingCopy) == true && fInfo->isWorkingCopy() == false) {
|
||||
AfxMessageBox( L"Cannot copy to Alfresco folder, destination must overwrite a working copy", MB_OK | MB_ICONEXCLAMATION);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if ( actionInfo.hasPreProcessAction(PreLocalToWorkingCopy) == true) {
|
||||
|
||||
// File is locked, may be the original document
|
||||
// Target folder does not contain a matching working copy of the local file
|
||||
|
||||
CString msg;
|
||||
msg.FormatMessage( L"No matching working copy for %1", curName.data());
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONEXCLAMATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy the files/folders using the Windows shell
|
||||
|
||||
bool copyAborted = false;
|
||||
|
||||
if ( copyFilesUsingShell( curFile, alfresco.getUNCPath(), copyAborted) == false) {
|
||||
|
||||
// Check if the copy failed or the user aborted the copy
|
||||
|
||||
if ( copyAborted == false) {
|
||||
|
||||
// File copy failed
|
||||
|
||||
CString msg;
|
||||
msg.FormatMessage( L"Destination file %1 is locked", curName.data());
|
||||
msg.FormatMessage( isDir ? L"Failed to copy folder %1" : L"Failed to copy file %1", curFile.data());
|
||||
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONSTOP);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
|
||||
// Indicate that we have copied a new file to the Alfresco share, do not check in/out
|
||||
// User aborted the file copy
|
||||
|
||||
copyFile = true;
|
||||
CString msg;
|
||||
msg.FormatMessage( L"Copy aborted for %1", curFile.data());
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONSTOP);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
// Indicate that we have copied a new file to the Alfresco share, do not check in/out
|
||||
// Add a desktop target for the copied file
|
||||
|
||||
copyFile = true;
|
||||
}
|
||||
|
||||
// Build the from/to paths, must be double null terminated
|
||||
|
||||
wchar_t fromPath[MAX_PATH + 1];
|
||||
wchar_t toPath[MAX_PATH + 1];
|
||||
|
||||
memset( fromPath, 0, sizeof( fromPath));
|
||||
memset( toPath, 0, sizeof( toPath));
|
||||
|
||||
wcscpy( fromPath, curFile.data());
|
||||
wcscpy( toPath, alfresco.getUNCPath());
|
||||
|
||||
// Copy the local file to the Alfresco folder
|
||||
|
||||
SHFILEOPSTRUCT fileOpStruct;
|
||||
memset( &fileOpStruct, 0, sizeof(SHFILEOPSTRUCT));
|
||||
|
||||
fileOpStruct.hwnd = HWND_DESKTOP;
|
||||
fileOpStruct.wFunc = FO_COPY;
|
||||
fileOpStruct.pFrom = fromPath;
|
||||
fileOpStruct.pTo = toPath;
|
||||
fileOpStruct.fFlags= 0;
|
||||
fileOpStruct.fAnyOperationsAborted =false;
|
||||
|
||||
// Copy the file to the Alfresco folder
|
||||
|
||||
if ( SHFileOperation( &fileOpStruct) != 0) {
|
||||
|
||||
// File copy failed
|
||||
|
||||
CString msg;
|
||||
msg.FormatMessage( L"Failed to copy file %1", curFile.data());
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONSTOP);
|
||||
return false;
|
||||
}
|
||||
else if ( fileOpStruct.fAnyOperationsAborted) {
|
||||
|
||||
// User aborted the file copy
|
||||
|
||||
CString msg;
|
||||
msg.FormatMessage( L"Copy aborted for %1", curFile.data());
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONSTOP);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the file information for the copied file
|
||||
|
||||
pFileInfo = alfresco.getFileInformation( curName);
|
||||
params.addTarget( new DesktopTarget(isDir ? TargetCopiedFolder : TargetCopiedFile, curName));
|
||||
}
|
||||
else {
|
||||
|
||||
// Check in or check out the file
|
||||
// Path is a UNC path, check if the file/folder is in the same folder as the action
|
||||
|
||||
if ( pFileInfo.get() != NULL) {
|
||||
DesktopTarget* pTarget = NULL;
|
||||
|
||||
// Check if the file should be checked in/out
|
||||
if ( curFile.startsWith( alfresco.getUNCPath())) {
|
||||
|
||||
if ( copyFile == false) {
|
||||
// Path is in the same folder as the application, or in a sub-folder
|
||||
|
||||
// Check if the file is a working copy, if so then check it in
|
||||
String relPath = curFile.substring( alfresco.getUNCPath().length() + 1);
|
||||
|
||||
if ( pFileInfo->isWorkingCopy()) {
|
||||
if ( relPath.indexOf( L"\\") == -1) {
|
||||
|
||||
// Check in the file
|
||||
// Create a target using the file name only
|
||||
|
||||
doCheckIn( alfresco, pFileInfo);
|
||||
pTarget = new DesktopTarget( isDir ? TargetFolder : TargetFile, relPath);
|
||||
}
|
||||
else if ( pFileInfo->getLockType() == LockNone) {
|
||||
}
|
||||
|
||||
// Check out the file
|
||||
// If the target is not valid the file/folder is not in the same folder as the client-side application,
|
||||
// copy the files/folders to the target folder or use the root relative path to the file/folder
|
||||
|
||||
doCheckOut( alfresco, pFileInfo);
|
||||
if ( pTarget == NULL) {
|
||||
|
||||
// Check if Alfresco files/folders should be copied to the target folder
|
||||
|
||||
if ( actionInfo.hasPreProcessAction(PreCopyToTarget)) {
|
||||
|
||||
// Copy the files/folders using the Windows shell
|
||||
|
||||
bool copyAborted = false;
|
||||
|
||||
if ( copyFilesUsingShell( curFile, alfresco.getUNCPath(), copyAborted) == false) {
|
||||
|
||||
// Check if the copy failed or the user aborted the copy
|
||||
|
||||
if ( copyAborted == false) {
|
||||
|
||||
// File copy failed
|
||||
|
||||
CString msg;
|
||||
msg.FormatMessage( isDir ? L"Failed to copy folder %1" : L"Failed to copy file %1", curFile.data());
|
||||
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONSTOP);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
|
||||
// User aborted the file copy
|
||||
|
||||
CString msg;
|
||||
msg.FormatMessage( L"Copy aborted for %1", curFile.data());
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONSTOP);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Add a desktop target for the copied file
|
||||
|
||||
pTarget= new DesktopTarget(isDir ? TargetCopiedFolder : TargetCopiedFile, curName);
|
||||
}
|
||||
else {
|
||||
|
||||
// File is locked, may already be checked out
|
||||
// Get the root relative path to the file/folder
|
||||
|
||||
CString msg;
|
||||
msg.FormatMessage( L"File %1 is locked", curFile.data());
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONSTOP);
|
||||
String rootRelPath = curFile.substring(alfresco.getRootPath().length());
|
||||
pTarget = new DesktopTarget( isDir ? TargetFolder : TargetFile, rootRelPath);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
// No existing file to link the copied file to
|
||||
|
||||
CString msg;
|
||||
msg.FormatMessage( L"Copied file %1 to Alfresco folder", curFile.data());
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONINFORMATION);
|
||||
}
|
||||
// Add the desktop target
|
||||
|
||||
params.addTarget( pTarget);
|
||||
}
|
||||
else {
|
||||
CString msg;
|
||||
msg.FormatMessage( L"Failed to get file status for %1", curFile.data());
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONSTOP);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
// Check the error status
|
||||
|
||||
CString msg;
|
||||
|
||||
if ( attr != INVALID_FILE_ATTRIBUTES)
|
||||
msg.FormatMessage( L"Path %1 is a folder, ignored", curFile.data());
|
||||
else
|
||||
msg.FormatMessage( L"File %1 does not exist", curFile.data());
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONSTOP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,74 +394,181 @@ bool CCAlfrescoAppApp::doCheckInOut( AlfrescoInterface& alfresco, StringList& fi
|
||||
}
|
||||
|
||||
/**
|
||||
* Check in the specified file
|
||||
* Copy a file/folder using the Windows shell
|
||||
*
|
||||
* @param alfresco AlfrescoInterface&
|
||||
* @param pFileInfo PTR_AlfrescoFileInfo&
|
||||
* @param fromFileFolder const String&
|
||||
* @param toFolder const String&
|
||||
* @param aborted bool&
|
||||
* @return bool
|
||||
*/
|
||||
bool CCAlfrescoAppApp::doCheckIn( AlfrescoInterface& alfresco, PTR_AlfrescoFileInfo& pFileInfo) {
|
||||
bool CCAlfrescoAppApp::copyFilesUsingShell(const String& fromFileFolder, const String& toFolder, bool& aborted) {
|
||||
|
||||
bool checkedIn = false;
|
||||
// Build the from/to paths, must be double null terminated
|
||||
|
||||
try {
|
||||
wchar_t fromPath[MAX_PATH + 1];
|
||||
wchar_t toPath[MAX_PATH + 1];
|
||||
|
||||
// Check in the specified file
|
||||
memset( fromPath, 0, sizeof( fromPath));
|
||||
memset( toPath, 0, sizeof( toPath));
|
||||
|
||||
alfresco.checkIn( pFileInfo->getName());
|
||||
wcscpy( fromPath, fromFileFolder.data());
|
||||
wcscpy( toPath, toFolder.data());
|
||||
|
||||
CString msg;
|
||||
msg.FormatMessage( L"Checked in file %1", pFileInfo->getName().data());
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONINFORMATION);
|
||||
// Copy the local file to the Alfresco folder
|
||||
|
||||
// Indicate that the check in was successful
|
||||
SHFILEOPSTRUCT fileOpStruct;
|
||||
memset( &fileOpStruct, 0, sizeof(SHFILEOPSTRUCT));
|
||||
|
||||
checkedIn = true;
|
||||
fileOpStruct.hwnd = HWND_DESKTOP;
|
||||
fileOpStruct.wFunc = FO_COPY;
|
||||
fileOpStruct.pFrom = fromPath;
|
||||
fileOpStruct.pTo = toPath;
|
||||
fileOpStruct.fFlags= 0;
|
||||
fileOpStruct.fAnyOperationsAborted =false;
|
||||
|
||||
// Copy the file to the Alfresco folder
|
||||
|
||||
bool sts = false;
|
||||
|
||||
if ( SHFileOperation( &fileOpStruct) == 0) {
|
||||
|
||||
// File copy successful
|
||||
|
||||
sts = true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
CString msg;
|
||||
msg.FormatMessage( L"Error checking in file %1\n\n%2", pFileInfo->getName().data(), ex.getMessage().data());
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONSTOP);
|
||||
else if ( fileOpStruct.fAnyOperationsAborted) {
|
||||
|
||||
// User aborted the file copy
|
||||
|
||||
aborted = true;
|
||||
}
|
||||
|
||||
// Return the check in status
|
||||
// Return the copy status
|
||||
|
||||
return checkedIn;
|
||||
return sts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check out the specified file
|
||||
* Run an action
|
||||
*
|
||||
* @param alfresco AlfrescoInterface&
|
||||
* @param pFileInfo PTR_AlfrescoFileInfo&
|
||||
* @param pathList StringList&
|
||||
* @param actionInfo AlfrescoActionInfo&
|
||||
* @return bool
|
||||
*/
|
||||
bool CCAlfrescoAppApp::doCheckOut( AlfrescoInterface& alfresco, PTR_AlfrescoFileInfo& pFileInfo) {
|
||||
bool CCAlfrescoAppApp::runAction( AlfrescoInterface& alfresco, StringList& pathList, AlfrescoActionInfo& actionInfo) {
|
||||
|
||||
bool checkedOut = false;
|
||||
// Build the desktop action parameter list, perform any file copying of local files
|
||||
|
||||
try {
|
||||
bool sts = false;
|
||||
DesktopParams desktopParams;
|
||||
|
||||
if ( buildDesktopParameters( alfresco, pathList, actionInfo, desktopParams)) {
|
||||
|
||||
// Check out the specified file
|
||||
// Check if the action requires parameters
|
||||
|
||||
String workingCopy;
|
||||
alfresco.checkOut( pFileInfo->getName(), workingCopy);
|
||||
if ( actionInfo.allowsNoParameters() == false && desktopParams.numberOfTargets() == 0) {
|
||||
AfxMessageBox( L"No parameters for action", MB_OK | MB_ICONEXCLAMATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
CString msg;
|
||||
msg.FormatMessage( L"Checked out file %1 to %2", pFileInfo->getName().data(), workingCopy.data());
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONINFORMATION);
|
||||
// Run the desktop action
|
||||
|
||||
// Indicate that the check out was successful
|
||||
DesktopResponse response = alfresco.runAction( actionInfo, desktopParams);
|
||||
|
||||
checkedOut = true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
CString msg;
|
||||
msg.FormatMessage( L"Error checking out file %1\n\n%2", pFileInfo->getName().data(), ex.getMessage().data());
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONSTOP);
|
||||
// Check the response status
|
||||
|
||||
if ( response.getStatus() != StsSuccess) {
|
||||
|
||||
// Check if the status indicates a command line should be launched
|
||||
|
||||
if ( response.getStatus() == StsCommandLine) {
|
||||
|
||||
// Initialize the startup information
|
||||
|
||||
STARTUPINFO startupInfo;
|
||||
memset(&startupInfo, 0, sizeof(STARTUPINFO));
|
||||
|
||||
// Launch a process using the command line
|
||||
|
||||
PROCESS_INFORMATION processInfo;
|
||||
memset(&processInfo, 0, sizeof(PROCESS_INFORMATION));
|
||||
|
||||
if ( CreateProcess( response.getStatusMessage().data(), NULL, NULL, NULL, true, 0, NULL, NULL,
|
||||
&startupInfo, &processInfo) == false) {
|
||||
CString msg;
|
||||
msg.FormatMessage( L"Failed to launch command line\n\n%1\n\nError %2!d!", response.getStatusMessage().data(), GetLastError());
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONERROR);
|
||||
}
|
||||
else
|
||||
sts = true;
|
||||
}
|
||||
|
||||
// Check if a web browser should be launched with a URL
|
||||
|
||||
else if ( response.getStatus() == StsLaunchURL) {
|
||||
|
||||
// Use the Windows shell to open the URL
|
||||
|
||||
HINSTANCE shellSts = ShellExecute( NULL, NULL, response.getStatusMessage().data(), NULL, NULL, SW_SHOWNORMAL);
|
||||
if (( int) shellSts < 32) {
|
||||
CString msg;
|
||||
msg.FormatMessage( L"Failed to launch URL\n\n%1", response.getStatusMessage().data());
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONERROR);
|
||||
}
|
||||
else
|
||||
sts = true;
|
||||
}
|
||||
|
||||
// Error status
|
||||
|
||||
else {
|
||||
|
||||
// Get the error message
|
||||
|
||||
String errMsg;
|
||||
|
||||
switch ( response.getStatus()) {
|
||||
case StsFileNotFound:
|
||||
errMsg = L"File not found";
|
||||
break;
|
||||
case StsAccessDenied:
|
||||
errMsg = L"Access denied";
|
||||
break;
|
||||
case StsBadParameter:
|
||||
errMsg = L"Bad parameter in request";
|
||||
break;
|
||||
case StsNoSuchAction:
|
||||
errMsg = L"No such action";
|
||||
break;
|
||||
default:
|
||||
errMsg = L"Error running action";
|
||||
break;
|
||||
}
|
||||
|
||||
// Display an error dialog
|
||||
|
||||
CString msg;
|
||||
|
||||
if ( response.hasStatusMessage())
|
||||
msg.FormatMessage( L"%1\n\n%2", errMsg.data(), response.getStatusMessage().data());
|
||||
else
|
||||
msg = errMsg.data();
|
||||
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONERROR);
|
||||
}
|
||||
}
|
||||
else if ( response.hasStatusMessage()) {
|
||||
|
||||
// Display the message returned by the action
|
||||
|
||||
CString msg;
|
||||
msg.FormatMessage( L"Action returned message\n\n%1", response.getStatusMessage().data());
|
||||
AfxMessageBox( msg, MB_OK | MB_ICONINFORMATION);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the check out status
|
||||
// Return the action status
|
||||
|
||||
return checkedOut;
|
||||
return sts;
|
||||
}
|
||||
|
Reference in New Issue
Block a user