riched20: Reduced screen flicker by using proper update region invalidation.
[wine/hacks.git] / programs / explorer / explorer.c
blobe57311061a44d0c254b0bb0755a3c8f34661bf50
1 /*
2 * explorer.exe
4 * Copyright 2005 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};
152 memset(&parameters,0,sizeof(parameters));
153 memset(&si,0,sizeof(STARTUPINFOW));
155 ParseCommandLine(cmdline,&parameters);
157 rc = CreateProcessW(NULL, winefile, NULL, NULL, FALSE, 0, NULL,
158 parameters.root, &si, &info);
160 if (!rc)
161 return 0;
163 WaitForSingleObject(info.hProcess,INFINITE);
164 return 0;