00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #define strict
00012
00013 #include <windows.h>
00014 #include <windowsx.h>
00015
00016 #include <commctrl.h>
00017
00018 #include <assert.h>
00019
00020 #include "persistent.h"
00021 #include "launcherconfig.h"
00022 #include "eclipselauncher.h"
00023 #include "registryhelper.h"
00024
00025
00026
00027
00028
00029
00030
00031 TCHAR* createConfigKey(int configNumber)
00032 {
00033 TCHAR* name = (TCHAR*) malloc(20);
00034 wsprintf(name, "Config%d", configNumber);
00035
00036 return name;
00037 }
00038
00039
00040
00041
00042
00043
00044
00045 TCHAR* createSectionKey(TCHAR* configKey)
00046 {
00047 TCHAR* sectionKey = (TCHAR*)malloc(BUFFERSIZE_256);
00048 wsprintf(sectionKey, "%s%s", REG_APP_KEY, configKey);
00049
00050 return sectionKey;
00051 }
00052
00053
00054
00055
00056
00057
00058
00059 void createConfigCountKey(int configurations)
00060 {
00061 TCHAR configCount[10] = {0};
00062 wsprintf(configCount, "%d", configurations);
00063
00064 CreateKey(REG_APP_KEY, KEY_CONFIGCOUNT, configCount);
00065 }
00066
00067
00068
00069
00070
00071
00072
00073 void loadConfiguration(HWND hListbox)
00074 {
00075 int bufferSize = 10;
00076 int tempBufferSize = BUFFERSIZE_512;
00077 int configurations;
00078 int i = 0;
00079
00080 TCHAR tempBuffer[BUFFERSIZE_512] = {0};
00081 TCHAR* config = (TCHAR*)malloc(bufferSize);
00082 ZeroMemory(config, bufferSize);
00083 QueryKey(HKEY_CURRENT_USER, REG_APP_KEY, KEY_CONFIGCOUNT, config, bufferSize);
00084
00085 configurations = atoi(config);
00086
00087 for(i = 0; i < configurations; i++)
00088 {
00089 LPLAUNCHERCONFIG launcherconfig = createLauncherConfig();
00090
00091 TCHAR* name = createConfigKey(i+1);
00092 TCHAR* section = createSectionKey(name);
00093
00094 QueryKey(HKEY_CURRENT_USER, section, KEY_CONFIGNAME, tempBuffer, tempBufferSize);
00095 setName(launcherconfig, tempBuffer, tempBufferSize);
00096
00097 QueryKey(HKEY_CURRENT_USER, section, KEY_EXECUTABLEPATH, tempBuffer, tempBufferSize);
00098 setExecutablePath(launcherconfig, tempBuffer, tempBufferSize);
00099
00100 QueryKey(HKEY_CURRENT_USER, section, KEY_OPTIONALPARAMETER, tempBuffer, tempBufferSize);
00101 setOptionalParameter(launcherconfig, tempBuffer, tempBufferSize);
00102
00103 QueryKey(HKEY_CURRENT_USER, section, KEY_WORKSPACEPATH, tempBuffer, tempBufferSize);
00104 setWorkspacePath(launcherconfig, tempBuffer, tempBufferSize);
00105
00106 QueryKey(HKEY_CURRENT_USER, section, KEY_VMPARAMETER, tempBuffer, tempBufferSize);
00107 setVMParameter(launcherconfig, tempBuffer, tempBufferSize);
00108
00109 QueryKey(HKEY_CURRENT_USER, section, KEY_ECLIPSEJAVAVM, tempBuffer, tempBufferSize);
00110 setJavaVM(launcherconfig, tempBuffer, tempBufferSize);
00111
00112 addLauchnerConfigToList(hListbox, launcherconfig, NEW_POSITION);
00113
00114 free(name);
00115 free(section);
00116 }
00117 }
00118
00119
00120
00121
00122
00123
00124
00125 void saveConfiguration(HWND hListbox)
00126 {
00127 int configurations = getConfigurationCount(hListbox);
00128
00129 if(configurations > 0)
00130 {
00131 int i;
00132 createConfigCountKey(configurations);
00133
00134 for(i = 0; i < configurations; i++)
00135 {
00136 LPLAUNCHERCONFIG launcherconfig = getLauncherConfig(hListbox, i);
00137
00138 TCHAR* name = createConfigKey(i+1);
00139 TCHAR* section = createSectionKey(name);
00140
00141 CreateKey(section, KEY_CONFIGNAME, getName(launcherconfig));
00142 CreateKey(section, KEY_EXECUTABLEPATH, getExecutablePath(launcherconfig));
00143 CreateKey(section, KEY_OPTIONALPARAMETER, getOptionalParameter(launcherconfig));
00144 CreateKey(section, KEY_WORKSPACEPATH, getWorkspacePath(launcherconfig));
00145 CreateKey(section, KEY_VMPARAMETER, getVMParameter(launcherconfig));
00146 CreateKey(section, KEY_ECLIPSEJAVAVM, getJavaVM(launcherconfig));
00147
00148 free(name);
00149 free(section);
00150 }
00151 }
00152 }
00153
00154
00155
00156
00157
00158
00159
00160 int getConfigurationCount(HWND hListBox)
00161 {
00162 return(ListView_GetItemCount(hListBox));
00163 }
00164
00165
00166
00167
00168
00169
00170
00171 LPLAUNCHERCONFIG getLauncherConfig(HWND hListBox, int currentSelection)
00172 {
00173 LV_ITEM item = {0};
00174 item.mask = LVIF_PARAM;
00175 item.iItem = currentSelection;
00176
00177 ListView_GetItem(hListBox, &item);
00178
00179 return((LPLAUNCHERCONFIG)item.lParam);
00180 }
00181
00182
00183
00184
00185
00186
00187
00188 int getCurrentSelection(HWND hListBox)
00189 {
00190 return(ListView_GetNextItem(hListBox, (-1), LVNI_SELECTED));
00191 }
00192
00200 BOOL setColumnValues(HWND hListBox, LPLAUNCHERCONFIG launcherConfig, int positionToInsertItem)
00201 {
00202 LV_ITEM item = {0};
00203
00204 item.mask = LVIF_TEXT;
00205 item.iItem = positionToInsertItem;
00206 item.iSubItem = 1;
00207 item.pszText = getWorkspacePath(launcherConfig);
00208
00209 ListView_SetItem(hListBox, &item);
00210
00211 item.iSubItem = 2;
00212 item.pszText = getJavaVM(launcherConfig);
00213
00214 ListView_SetItem(hListBox, &item);
00215
00216 item.iSubItem = 3;
00217 item.pszText = getVMParameter(launcherConfig);
00218
00219 return ListView_SetItem(hListBox, &item);
00220 }
00221
00222
00223
00224
00225
00226
00227
00228 BOOL addLauchnerConfigToList(HWND hListBox, LPLAUNCHERCONFIG launcherConfig, int positionToInsertItem)
00229 {
00230 LV_ITEM item = {0};
00231 int newInsertedPosition;
00232
00233 int newPos = positionToInsertItem;
00234
00235 assert(launcherConfig != NULL);
00236
00237 if(newPos == NEW_POSITION)
00238 {
00239 newPos = ListView_GetItemCount(hListBox);
00240 }
00241
00242 item.mask = LVIF_TEXT | LVIF_PARAM;
00243 item.iItem = newPos;
00244 item.iSubItem = 0;
00245 item.pszText = getName(launcherConfig);
00246 item.lParam = (LPARAM)launcherConfig;
00247
00248 newInsertedPosition = ListView_InsertItem(hListBox, &item);
00249
00250 return setColumnValues(hListBox, launcherConfig, newInsertedPosition);
00251 }
00252
00253
00254
00255
00256
00257
00258
00259 BOOL updateLauchnerConfig(HWND hListBox, LPLAUNCHERCONFIG launcherConfig, int positionToInsertItem)
00260 {
00261 LV_ITEM item = {0};
00262
00263 assert(launcherConfig != NULL);
00264
00265 item.mask = LVIF_TEXT | LVIF_PARAM;
00266 item.iItem = positionToInsertItem;
00267 item.iSubItem = 0;
00268 item.pszText = getName(launcherConfig);
00269 item.lParam = (LPARAM)launcherConfig;
00270
00271 ListView_SetItem(hListBox, &item);
00272
00273 setColumnValues(hListBox, launcherConfig, positionToInsertItem);
00274
00275 return(ListView_Update(hListBox, positionToInsertItem));
00276 }