oleaut32: Reimplement VarCmp().
[wine/multimedia.git] / programs / explorer / explorer.c
bloba8cb2602de91995d8871b35f78ee46f0d34aacf5
1 /*
2 * explorer.exe
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
21 #include <windows.h>
22 #include <ctype.h>
24 typedef struct parametersTAG {
25 BOOL explorer_mode;
26 WCHAR root[MAX_PATH];
27 WCHAR selection[MAX_PATH];
28 } parameters_struct;
31 static int CopyPathString(LPWSTR target, LPSTR source)
33 CHAR temp_buf[MAX_PATH];
34 INT i = 0;
36 while (isspace(*source)) source++;
38 if (*source == '\"')
40 source ++;
41 while (*source != '\"')
43 temp_buf[i] = *source;
44 i++;
45 source++;
47 temp_buf[i] = 0;
48 source ++;
49 i+=2;
51 else
53 while (*source && !isspace(*source))
55 temp_buf[i] = *source;
56 i++;
57 source++;
59 temp_buf[i] = 0;
61 MultiByteToWideChar(CP_ACP,0,temp_buf,-1,target,MAX_PATH);
62 return i;
66 static void CopyPathRoot(LPWSTR root, LPWSTR path)
68 LPWSTR p,p2;
69 INT i = 0;
71 p = path;
72 while (*p!=0)
73 p++;
75 while (*p!='\\' && p > path)
76 p--;
78 if (p == path)
79 return;
81 p2 = path;
82 while (p2 != p)
84 root[i] = *p2;
85 i++;
86 p2++;
88 root[i] = 0;
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)
100 LPSTR p;
101 LPSTR p2;
103 p2 = commandline;
104 p = strchr(commandline,'/');
105 while(p)
107 p++;
108 if (strncmp(p,"n",1)==0)
110 parameters->explorer_mode = FALSE;
111 p++;
113 else if (strncmp(p,"e,",2)==0)
115 parameters->explorer_mode = TRUE;
116 p+=2;
118 else if (strncmp(p,"root,",5)==0)
120 p+=5;
121 p+=CopyPathString(parameters->root,p);
123 else if (strncmp(p,"select,",7)==0)
125 p+=7;
126 p+=CopyPathString(parameters->selection,p);
127 if (!parameters->root[0])
128 CopyPathRoot(parameters->root,
129 parameters->selection);
131 p2 = p;
132 p = strchr(p,'/');
134 if (p2 && *p2)
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,
143 LPSTR cmdline,
144 int cmdshow)
146 STARTUPINFOW si;
147 PROCESS_INFORMATION info;
148 parameters_struct parameters;
149 BOOL rc;
150 static WCHAR winefile[] = {'w','i','n','e','f','i','l','e','.','e','x','e',0};
151 static WCHAR space[] = {' ',0};
152 LPWSTR winefile_commandline = NULL;
153 DWORD len = 0;
155 memset(&parameters,0,sizeof(parameters));
156 memset(&si,0,sizeof(STARTUPINFOW));
158 ParseCommandLine(cmdline,&parameters);
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);
184 else
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);
195 if (!rc)
196 return 0;
198 WaitForSingleObject(info.hProcess,INFINITE);
199 return 0;