2005-11-16 11:45:51 +00:00
|
|
|
/*
|
|
|
|
* explorer.exe
|
|
|
|
*
|
2006-02-19 17:50:27 +00:00
|
|
|
* Copyright 2004 CodeWeavers, Mike Hearn
|
2006-01-14 16:05:18 +00:00
|
|
|
* Copyright 2005,2006 CodeWeavers, Aric Stewart
|
2011-06-11 21:42:17 +00:00
|
|
|
* Copyright 2011 Jay Yang
|
2005-11-16 11:45:51 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-11-16 11:45:51 +00:00
|
|
|
*/
|
|
|
|
|
2011-06-11 21:42:17 +00:00
|
|
|
#define COBJMACROS
|
2005-11-16 11:45:51 +00:00
|
|
|
|
2008-04-23 16:04:43 +00:00
|
|
|
#include "wine/unicode.h"
|
2011-06-11 21:42:17 +00:00
|
|
|
#include "wine/debug.h"
|
2006-03-07 10:41:52 +00:00
|
|
|
#include "explorer_private.h"
|
2011-06-11 21:42:17 +00:00
|
|
|
#include "resource.h"
|
|
|
|
|
|
|
|
#include <initguid.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <shobjidl.h>
|
|
|
|
#include <shlobj.h>
|
|
|
|
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(explorer);
|
|
|
|
|
|
|
|
#define EXPLORER_INFO_INDEX 0
|
|
|
|
|
|
|
|
#define DEFAULT_WIDTH 640
|
|
|
|
#define DEFAULT_HEIGHT 480
|
|
|
|
|
|
|
|
|
|
|
|
static const WCHAR EXPLORER_CLASS[] = {'W','I','N','E','_','E','X','P','L','O','R','E','R','\0'};
|
|
|
|
|
|
|
|
HINSTANCE explorer_hInstance;
|
2006-02-19 17:50:27 +00:00
|
|
|
|
2005-11-16 11:45:51 +00:00
|
|
|
typedef struct parametersTAG {
|
|
|
|
BOOL explorer_mode;
|
|
|
|
WCHAR root[MAX_PATH];
|
|
|
|
WCHAR selection[MAX_PATH];
|
|
|
|
} parameters_struct;
|
|
|
|
|
2011-06-11 21:42:17 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
IExplorerBrowser *browser;
|
|
|
|
} explorer_info;
|
|
|
|
|
|
|
|
static void make_explorer_window(IShellFolder* startFolder)
|
|
|
|
{
|
|
|
|
RECT explorerRect;
|
|
|
|
HWND window;
|
|
|
|
FOLDERSETTINGS fs;
|
|
|
|
explorer_info *info;
|
|
|
|
HRESULT hres;
|
|
|
|
WCHAR explorer_title[100];
|
|
|
|
LoadStringW(explorer_hInstance,IDS_EXPLORER_TITLE,explorer_title,
|
|
|
|
sizeof(explorer_title)/sizeof(WCHAR));
|
|
|
|
info = HeapAlloc(GetProcessHeap(),0,sizeof(explorer_info));
|
|
|
|
if(!info)
|
|
|
|
{
|
|
|
|
WINE_ERR("Could not allocate a explorer_info struct\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hres = CoCreateInstance(&CLSID_ExplorerBrowser,NULL,CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IExplorerBrowser,(LPVOID*)&info->browser);
|
|
|
|
if(!SUCCEEDED(hres))
|
|
|
|
{
|
|
|
|
WINE_ERR("Could not obtain an instance of IExplorerBrowser\n");
|
|
|
|
HeapFree(GetProcessHeap(),0,info);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window = CreateWindowW(EXPLORER_CLASS,explorer_title,WS_OVERLAPPEDWINDOW,
|
|
|
|
CW_USEDEFAULT,CW_USEDEFAULT,DEFAULT_WIDTH,
|
|
|
|
DEFAULT_HEIGHT,NULL,NULL,explorer_hInstance,NULL);
|
|
|
|
fs.ViewMode = FVM_DETAILS;
|
|
|
|
fs.fFlags = FWF_AUTOARRANGE;
|
|
|
|
explorerRect.left = 0;
|
|
|
|
explorerRect.top = 0;
|
|
|
|
explorerRect.right = DEFAULT_WIDTH;
|
|
|
|
explorerRect.bottom = DEFAULT_HEIGHT;
|
|
|
|
|
|
|
|
IExplorerBrowser_Initialize(info->browser,window,&explorerRect,&fs);
|
|
|
|
IExplorerBrowser_SetOptions(info->browser,EBO_SHOWFRAMES);
|
|
|
|
SetWindowLongPtrW(window,EXPLORER_INFO_INDEX,(LONG_PTR)info);
|
|
|
|
IExplorerBrowser_BrowseToObject(info->browser,(IUnknown*)startFolder,
|
|
|
|
SBSP_ABSOLUTE);
|
|
|
|
ShowWindow(window,SW_SHOWDEFAULT);
|
|
|
|
UpdateWindow(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_window_size(explorer_info *info, int height, int width)
|
|
|
|
{
|
|
|
|
RECT new_rect;
|
|
|
|
new_rect.left = 0;
|
|
|
|
new_rect.top = 0;
|
|
|
|
new_rect.right = width;
|
|
|
|
new_rect.bottom = height;
|
|
|
|
IExplorerBrowser_SetRect(info->browser,NULL,new_rect);
|
|
|
|
}
|
2005-11-16 11:45:51 +00:00
|
|
|
|
2011-06-11 21:42:17 +00:00
|
|
|
static void do_exit(int code)
|
|
|
|
{
|
|
|
|
OleUninitialize();
|
|
|
|
ExitProcess(code);
|
|
|
|
}
|
|
|
|
|
2011-06-19 12:09:31 +00:00
|
|
|
static LRESULT CALLBACK explorer_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2011-06-11 21:42:17 +00:00
|
|
|
{
|
|
|
|
explorer_info *info
|
|
|
|
= (explorer_info*)GetWindowLongPtrW(hwnd,EXPLORER_INFO_INDEX);
|
|
|
|
IExplorerBrowser *browser = NULL;
|
|
|
|
|
|
|
|
if(info)
|
|
|
|
browser = info->browser;
|
|
|
|
switch(uMsg)
|
|
|
|
{
|
|
|
|
case WM_DESTROY:
|
|
|
|
IExplorerBrowser_Release(browser);
|
|
|
|
HeapFree(GetProcessHeap(),0,info);
|
|
|
|
PostQuitMessage(0);
|
|
|
|
break;
|
|
|
|
case WM_QUIT:
|
|
|
|
do_exit(wParam);
|
|
|
|
case WM_SIZE:
|
|
|
|
update_window_size(info,HIWORD(lParam),LOWORD(lParam));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return DefWindowProcW(hwnd,uMsg,wParam,lParam);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void register_explorer_window_class(void)
|
|
|
|
{
|
|
|
|
WNDCLASSEXW window_class;
|
|
|
|
window_class.cbSize = sizeof(WNDCLASSEXW);
|
|
|
|
window_class.style = 0;
|
|
|
|
window_class.cbClsExtra = 0;
|
|
|
|
window_class.cbWndExtra = sizeof(LONG_PTR);
|
|
|
|
window_class.lpfnWndProc = explorer_wnd_proc;
|
|
|
|
window_class.hInstance = explorer_hInstance;
|
|
|
|
window_class.hIcon = NULL;
|
|
|
|
window_class.hCursor = NULL;
|
|
|
|
window_class.hbrBackground = NULL;
|
|
|
|
window_class.lpszMenuName = NULL;
|
|
|
|
window_class.lpszClassName = EXPLORER_CLASS;
|
|
|
|
window_class.hIconSm = NULL;
|
|
|
|
RegisterClassExW(&window_class);
|
|
|
|
}
|
|
|
|
|
2011-06-11 21:42:21 +00:00
|
|
|
static IShellFolder* get_starting_shell_folder(parameters_struct* params)
|
|
|
|
{
|
|
|
|
IShellFolder* desktop,*folder;
|
|
|
|
LPITEMIDLIST root_pidl;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
SHGetDesktopFolder(&desktop);
|
2011-06-28 06:31:31 +00:00
|
|
|
if (!params->root[0])
|
2011-06-11 21:42:21 +00:00
|
|
|
{
|
|
|
|
return desktop;
|
|
|
|
}
|
|
|
|
hres = IShellFolder_ParseDisplayName(desktop,NULL,NULL,
|
|
|
|
params->root,NULL,
|
|
|
|
&root_pidl,NULL);
|
|
|
|
|
|
|
|
if(FAILED(hres))
|
|
|
|
{
|
|
|
|
return desktop;
|
|
|
|
}
|
|
|
|
hres = IShellFolder_BindToObject(desktop,root_pidl,NULL,
|
|
|
|
&IID_IShellFolder,
|
|
|
|
(void**)&folder);
|
|
|
|
if(FAILED(hres))
|
|
|
|
{
|
|
|
|
return desktop;
|
|
|
|
}
|
|
|
|
IShellFolder_Release(desktop);
|
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
|
2011-06-11 21:42:17 +00:00
|
|
|
static int copy_path_string(LPWSTR target, LPWSTR source)
|
2005-11-16 11:45:51 +00:00
|
|
|
{
|
|
|
|
INT i = 0;
|
|
|
|
|
2008-04-23 16:04:43 +00:00
|
|
|
while (isspaceW(*source)) source++;
|
2005-11-16 11:45:51 +00:00
|
|
|
|
|
|
|
if (*source == '\"')
|
|
|
|
{
|
|
|
|
source ++;
|
2008-04-23 16:04:43 +00:00
|
|
|
while (*source != '\"') target[i++] = *source++;
|
|
|
|
target[i] = 0;
|
2005-11-16 11:45:51 +00:00
|
|
|
source ++;
|
|
|
|
i+=2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-23 16:04:43 +00:00
|
|
|
while (*source && !isspaceW(*source)) target[i++] = *source++;
|
|
|
|
target[i] = 0;
|
2005-11-16 11:45:51 +00:00
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-11 21:42:17 +00:00
|
|
|
static void copy_path_root(LPWSTR root, LPWSTR path)
|
2005-11-16 11:45:51 +00:00
|
|
|
{
|
|
|
|
LPWSTR p,p2;
|
|
|
|
INT i = 0;
|
|
|
|
|
|
|
|
p = path;
|
|
|
|
while (*p!=0)
|
|
|
|
p++;
|
|
|
|
|
|
|
|
while (*p!='\\' && p > path)
|
|
|
|
p--;
|
|
|
|
|
|
|
|
if (p == path)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p2 = path;
|
|
|
|
while (p2 != p)
|
|
|
|
{
|
|
|
|
root[i] = *p2;
|
|
|
|
i++;
|
|
|
|
p2++;
|
|
|
|
}
|
|
|
|
root[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Command Line parameters are:
|
|
|
|
* [/n] Opens in single-paned view for each selected items. This is default
|
|
|
|
* [/e,] Uses Windows Explorer View
|
|
|
|
* [/root,object] Specifies the root level of the view
|
|
|
|
* [/select,object] parent folder is opened and specified object is selected
|
|
|
|
*/
|
2011-06-11 21:42:17 +00:00
|
|
|
static void parse_command_line(LPWSTR commandline,parameters_struct *parameters)
|
2005-11-16 11:45:51 +00:00
|
|
|
{
|
2008-04-23 16:04:43 +00:00
|
|
|
static const WCHAR arg_n[] = {'/','n'};
|
|
|
|
static const WCHAR arg_e[] = {'/','e',','};
|
|
|
|
static const WCHAR arg_root[] = {'/','r','o','o','t',','};
|
|
|
|
static const WCHAR arg_select[] = {'/','s','e','l','e','c','t',','};
|
|
|
|
static const WCHAR arg_desktop[] = {'/','d','e','s','k','t','o','p'};
|
|
|
|
|
|
|
|
LPWSTR p, p2;
|
|
|
|
|
2005-11-16 11:45:51 +00:00
|
|
|
p2 = commandline;
|
2008-04-23 16:04:43 +00:00
|
|
|
p = strchrW(commandline,'/');
|
2005-11-16 11:45:51 +00:00
|
|
|
while(p)
|
|
|
|
{
|
2008-04-23 16:04:43 +00:00
|
|
|
if (strncmpW(p, arg_n, sizeof(arg_n)/sizeof(WCHAR))==0)
|
2005-11-16 11:45:51 +00:00
|
|
|
{
|
|
|
|
parameters->explorer_mode = FALSE;
|
2008-04-23 16:04:43 +00:00
|
|
|
p += sizeof(arg_n)/sizeof(WCHAR);
|
2005-11-16 11:45:51 +00:00
|
|
|
}
|
2008-04-23 16:04:43 +00:00
|
|
|
else if (strncmpW(p, arg_e, sizeof(arg_e)/sizeof(WCHAR))==0)
|
2005-11-16 11:45:51 +00:00
|
|
|
{
|
|
|
|
parameters->explorer_mode = TRUE;
|
2008-04-23 16:04:43 +00:00
|
|
|
p += sizeof(arg_e)/sizeof(WCHAR);
|
2005-11-16 11:45:51 +00:00
|
|
|
}
|
2008-04-23 16:04:43 +00:00
|
|
|
else if (strncmpW(p, arg_root, sizeof(arg_root)/sizeof(WCHAR))==0)
|
2005-11-16 11:45:51 +00:00
|
|
|
{
|
2008-04-23 16:04:43 +00:00
|
|
|
p += sizeof(arg_root)/sizeof(WCHAR);
|
2011-06-11 21:42:17 +00:00
|
|
|
p+=copy_path_string(parameters->root,p);
|
2005-11-16 11:45:51 +00:00
|
|
|
}
|
2008-04-23 16:04:43 +00:00
|
|
|
else if (strncmpW(p, arg_select, sizeof(arg_select)/sizeof(WCHAR))==0)
|
2005-11-16 11:45:51 +00:00
|
|
|
{
|
2008-04-23 16:04:43 +00:00
|
|
|
p += sizeof(arg_select)/sizeof(WCHAR);
|
2011-06-11 21:42:17 +00:00
|
|
|
p+=copy_path_string(parameters->selection,p);
|
2005-11-16 11:45:51 +00:00
|
|
|
if (!parameters->root[0])
|
2011-06-11 21:42:17 +00:00
|
|
|
copy_path_root(parameters->root,
|
|
|
|
parameters->selection);
|
2005-11-16 11:45:51 +00:00
|
|
|
}
|
2008-04-23 16:04:43 +00:00
|
|
|
else if (strncmpW(p, arg_desktop, sizeof(arg_desktop)/sizeof(WCHAR))==0)
|
2006-03-07 10:41:52 +00:00
|
|
|
{
|
2008-04-23 16:04:43 +00:00
|
|
|
p += sizeof(arg_desktop)/sizeof(WCHAR);
|
|
|
|
manage_desktop( p ); /* the rest of the command line is handled by desktop mode */
|
2006-03-07 10:41:52 +00:00
|
|
|
}
|
2008-04-23 16:04:43 +00:00
|
|
|
else p++;
|
|
|
|
|
2005-11-16 11:45:51 +00:00
|
|
|
p2 = p;
|
2008-04-23 16:04:43 +00:00
|
|
|
p = strchrW(p,'/');
|
2005-11-16 11:45:51 +00:00
|
|
|
}
|
|
|
|
if (p2 && *p2)
|
|
|
|
{
|
|
|
|
/* left over command line is generally the path to be opened */
|
2011-06-11 21:42:17 +00:00
|
|
|
copy_path_string(parameters->root,p2);
|
2005-11-16 11:45:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-23 16:04:43 +00:00
|
|
|
int WINAPI wWinMain(HINSTANCE hinstance,
|
|
|
|
HINSTANCE previnstance,
|
|
|
|
LPWSTR cmdline,
|
|
|
|
int cmdshow)
|
2005-11-16 11:45:51 +00:00
|
|
|
{
|
2011-06-11 21:42:17 +00:00
|
|
|
|
2005-11-16 11:45:51 +00:00
|
|
|
parameters_struct parameters;
|
2011-06-11 21:42:17 +00:00
|
|
|
HRESULT hres;
|
|
|
|
MSG msg;
|
|
|
|
IShellFolder *folder;
|
2005-11-16 11:45:51 +00:00
|
|
|
|
|
|
|
memset(¶meters,0,sizeof(parameters));
|
2011-06-11 21:42:17 +00:00
|
|
|
explorer_hInstance = hinstance;
|
|
|
|
parse_command_line(cmdline,¶meters);
|
|
|
|
hres = OleInitialize(NULL);
|
|
|
|
if(!SUCCEEDED(hres))
|
2006-01-14 16:05:18 +00:00
|
|
|
{
|
2011-06-11 21:42:17 +00:00
|
|
|
WINE_ERR("Could not initialize COM\n");
|
|
|
|
ExitProcess(EXIT_FAILURE);
|
2006-01-14 16:05:18 +00:00
|
|
|
}
|
2011-06-11 21:42:17 +00:00
|
|
|
register_explorer_window_class();
|
2011-06-11 21:42:21 +00:00
|
|
|
folder = get_starting_shell_folder(¶meters);
|
2011-06-11 21:42:17 +00:00
|
|
|
make_explorer_window(folder);
|
|
|
|
IShellFolder_Release(folder);
|
|
|
|
while(GetMessageW( &msg, NULL, 0, 0 ) != 0)
|
2006-01-14 16:05:18 +00:00
|
|
|
{
|
2011-06-11 21:42:17 +00:00
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessageW(&msg);
|
2006-01-14 16:05:18 +00:00
|
|
|
}
|
2005-11-16 11:45:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|