4 * Copyright 2005,2006 CodeWeavers, Aric Stewart
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 typedef struct parametersTAG {
27 WCHAR selection[MAX_PATH];
31 static int CopyPathString(LPWSTR target, LPSTR source)
33 CHAR temp_buf[MAX_PATH];
36 while (isspace(*source)) source++;
41 while (*source != '\"')
43 temp_buf[i] = *source;
53 while (*source && !isspace(*source))
55 temp_buf[i] = *source;
61 MultiByteToWideChar(CP_ACP,0,temp_buf,-1,target,MAX_PATH);
66 static void CopyPathRoot(LPWSTR root, LPWSTR path)
75 while (*p!='\\' && p > path)
92 * Command Line parameters are:
93 * [/n] Opens in single-paned view for each selected items. This is default
94 * [/e,] Uses Windows Explorer View
95 * [/root,object] Specifies the root level of the view
96 * [/select,object] parent folder is opened and specified object is selected
98 static void ParseCommandLine(LPSTR commandline,parameters_struct *parameters)
104 p = strchr(commandline,'/');
108 if (strncmp(p,"n",1)==0)
110 parameters->explorer_mode = FALSE;
113 else if (strncmp(p,"e,",2)==0)
115 parameters->explorer_mode = TRUE;
118 else if (strncmp(p,"root,",5)==0)
121 p+=CopyPathString(parameters->root,p);
123 else if (strncmp(p,"select,",7)==0)
126 p+=CopyPathString(parameters->selection,p);
127 if (!parameters->root[0])
128 CopyPathRoot(parameters->root,
129 parameters->selection);
136 /* left over command line is generally the path to be opened */
137 CopyPathString(parameters->root,p2);
141 int WINAPI WinMain(HINSTANCE hinstance,
142 HINSTANCE previnstance,
147 PROCESS_INFORMATION info;
148 parameters_struct parameters;
150 static const WCHAR winefile[] = {'w','i','n','e','f','i','l','e','.','e','x','e',0};
151 static const WCHAR space[] = {' ',0};
152 LPWSTR winefile_commandline = NULL;
155 memset(¶meters,0,sizeof(parameters));
156 memset(&si,0,sizeof(STARTUPINFOW));
158 ParseCommandLine(cmdline,¶meters);
159 len = lstrlenW(winefile) +1;
161 if (parameters.selection[0])
163 len += lstrlenW(parameters.selection) + 2;
164 winefile_commandline = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
166 lstrcpyW(winefile_commandline,winefile);
167 lstrcatW(winefile_commandline,space);
168 lstrcatW(winefile_commandline,parameters.selection);
170 else if (parameters.root[0])
172 len += lstrlenW(parameters.root) + 3;
173 winefile_commandline = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
175 lstrcpyW(winefile_commandline,winefile);
176 lstrcatW(winefile_commandline,space);
177 lstrcatW(winefile_commandline,parameters.root);
178 if (winefile_commandline[lstrlenW(winefile_commandline)-1]!='\\')
180 static const WCHAR slash[] = {'\\',0};
181 lstrcatW(winefile_commandline,slash);
186 winefile_commandline = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
187 lstrcpyW(winefile_commandline,winefile);
190 rc = CreateProcessW(NULL, winefile_commandline, NULL, NULL, FALSE, 0, NULL,
191 parameters.root, &si, &info);
193 HeapFree(GetProcessHeap(),0,winefile_commandline);
198 WaitForSingleObject(info.hProcess,INFINITE);