4 * Copyright 2004 CodeWeavers, Mike Hearn
5 * Copyright 2005,2006 CodeWeavers, Aric Stewart
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/unicode.h"
25 #include "explorer_private.h"
27 typedef struct parametersTAG {
30 WCHAR selection[MAX_PATH];
34 static int CopyPathString(LPWSTR target, LPWSTR source)
38 while (isspaceW(*source)) source++;
43 while (*source != '\"') target[i++] = *source++;
50 while (*source && !isspaceW(*source)) target[i++] = *source++;
57 static void CopyPathRoot(LPWSTR root, LPWSTR path)
66 while (*p!='\\' && p > path)
83 * Command Line parameters are:
84 * [/n] Opens in single-paned view for each selected items. This is default
85 * [/e,] Uses Windows Explorer View
86 * [/root,object] Specifies the root level of the view
87 * [/select,object] parent folder is opened and specified object is selected
89 static void ParseCommandLine(LPWSTR commandline,parameters_struct *parameters)
91 static const WCHAR arg_n[] = {'/','n'};
92 static const WCHAR arg_e[] = {'/','e',','};
93 static const WCHAR arg_root[] = {'/','r','o','o','t',','};
94 static const WCHAR arg_select[] = {'/','s','e','l','e','c','t',','};
95 static const WCHAR arg_desktop[] = {'/','d','e','s','k','t','o','p'};
100 p = strchrW(commandline,'/');
103 if (strncmpW(p, arg_n, sizeof(arg_n)/sizeof(WCHAR))==0)
105 parameters->explorer_mode = FALSE;
106 p += sizeof(arg_n)/sizeof(WCHAR);
108 else if (strncmpW(p, arg_e, sizeof(arg_e)/sizeof(WCHAR))==0)
110 parameters->explorer_mode = TRUE;
111 p += sizeof(arg_e)/sizeof(WCHAR);
113 else if (strncmpW(p, arg_root, sizeof(arg_root)/sizeof(WCHAR))==0)
115 p += sizeof(arg_root)/sizeof(WCHAR);
116 p+=CopyPathString(parameters->root,p);
118 else if (strncmpW(p, arg_select, sizeof(arg_select)/sizeof(WCHAR))==0)
120 p += sizeof(arg_select)/sizeof(WCHAR);
121 p+=CopyPathString(parameters->selection,p);
122 if (!parameters->root[0])
123 CopyPathRoot(parameters->root,
124 parameters->selection);
126 else if (strncmpW(p, arg_desktop, sizeof(arg_desktop)/sizeof(WCHAR))==0)
128 p += sizeof(arg_desktop)/sizeof(WCHAR);
129 manage_desktop( p ); /* the rest of the command line is handled by desktop mode */
138 /* left over command line is generally the path to be opened */
139 CopyPathString(parameters->root,p2);
143 int WINAPI wWinMain(HINSTANCE hinstance,
144 HINSTANCE previnstance,
149 PROCESS_INFORMATION info;
150 parameters_struct parameters;
152 static const WCHAR winefile[] = {'\\','w','i','n','e','f','i','l','e','.','e','x','e',0};
153 static const WCHAR space[] = {' ',0};
154 LPWSTR winefile_commandline = NULL;
157 memset(¶meters,0,sizeof(parameters));
158 memset(&si,0,sizeof(STARTUPINFOW));
160 ParseCommandLine(cmdline,¶meters);
161 len = GetSystemDirectoryW( NULL, 0 ) + sizeof(winefile)/sizeof(WCHAR);
163 if (parameters.selection[0]) len += lstrlenW(parameters.selection) + 2;
164 else if (parameters.root[0]) len += lstrlenW(parameters.root) + 3;
166 winefile_commandline = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
167 GetSystemDirectoryW( winefile_commandline, len );
168 lstrcatW(winefile_commandline,winefile);
170 if (parameters.selection[0])
172 lstrcatW(winefile_commandline,space);
173 lstrcatW(winefile_commandline,parameters.selection);
175 else if (parameters.root[0])
177 lstrcatW(winefile_commandline,space);
178 lstrcatW(winefile_commandline,parameters.root);
179 if (winefile_commandline[lstrlenW(winefile_commandline)-1]!='\\')
181 static const WCHAR slash[] = {'\\',0};
182 lstrcatW(winefile_commandline,slash);
186 rc = CreateProcessW(NULL, winefile_commandline, NULL, NULL, FALSE, 0, NULL,
187 parameters.root, &si, &info);
189 HeapFree(GetProcessHeap(),0,winefile_commandline);
194 CloseHandle(info.hThread);
195 WaitForSingleObject(info.hProcess,INFINITE);
196 CloseHandle(info.hProcess);