00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "launcherconfig.h"
00012 #include <assert.h>
00013
00014
00015
00016
00017
00018
00019
00020 LPLAUNCHERCONFIG createLauncherConfig()
00021 {
00022 LPLAUNCHERCONFIG newLauncherConfig = (LPLAUNCHERCONFIG)malloc(sizeof(struct LAUNCHERCONFIG));
00023
00024 memset(newLauncherConfig, 0, sizeof(LCONFIG));
00025 allocateMemberMemory(newLauncherConfig);
00026
00027 return newLauncherConfig;
00028 }
00029
00030
00031
00032
00033
00034
00035
00036 LPLAUNCHERCONFIG createLauncherConfigCopy(LPLAUNCHERCONFIG launcherConfig)
00037 {
00038 LPLAUNCHERCONFIG newLauncherConfig;
00039
00040 assert(launcherConfig != NULL);
00041
00042 newLauncherConfig = createLauncherConfig();
00043
00044 return copyLauncherConfigToMemoryBlock(newLauncherConfig, launcherConfig);
00045 }
00046
00047
00048
00049
00050
00051
00052
00053 LPLAUNCHERCONFIG copyLauncherConfigToMemoryBlock(LPLAUNCHERCONFIG destinationConfiguration, LPLAUNCHERCONFIG launcherConfig)
00054 {
00055 assert(destinationConfiguration != NULL);
00056 assert(launcherConfig != NULL);
00057
00058 allocateMemberMemory(destinationConfiguration);
00059
00060 lstrcpyn(destinationConfiguration->name, launcherConfig->name, MAX_STRING_LENGTH);
00061 lstrcpyn(destinationConfiguration->executablePath, launcherConfig->executablePath, MAX_STRING_LENGTH);
00062 lstrcpyn(destinationConfiguration->optionalParams, launcherConfig->optionalParams, MAX_STRING_LENGTH);
00063 lstrcpyn(destinationConfiguration->workspacePath, launcherConfig->workspacePath, MAX_STRING_LENGTH);
00064 lstrcpyn(destinationConfiguration->vmParamter, launcherConfig->vmParamter, MAX_STRING_LENGTH);
00065 lstrcpyn(destinationConfiguration->javaVM, launcherConfig->javaVM, MAX_STRING_LENGTH);
00066 destinationConfiguration->isCurrentlyRunning = launcherConfig->isCurrentlyRunning;
00067
00068 return destinationConfiguration;
00069 }
00070
00071
00072
00073
00074
00075
00076
00077 void allocateMemberMemory(LPLAUNCHERCONFIG newLauncherConfig)
00078 {
00079 assert(newLauncherConfig != NULL);
00080
00081 newLauncherConfig->name = (TCHAR*)malloc(MAX_STRING_LENGTH);
00082 newLauncherConfig->executablePath = (TCHAR*)malloc(MAX_STRING_LENGTH);
00083 newLauncherConfig->optionalParams = (TCHAR*)malloc(MAX_STRING_LENGTH);
00084 newLauncherConfig->workspacePath = (TCHAR*)malloc(MAX_STRING_LENGTH);
00085 newLauncherConfig->vmParamter = (TCHAR*)malloc(MAX_STRING_LENGTH);
00086 newLauncherConfig->javaVM = (TCHAR*)malloc(MAX_STRING_LENGTH);
00087 newLauncherConfig->isCurrentlyRunning = FALSE;
00088
00089 ZeroMemory(newLauncherConfig->name, MAX_STRING_LENGTH);
00090 ZeroMemory(newLauncherConfig->executablePath, MAX_STRING_LENGTH);
00091 ZeroMemory(newLauncherConfig->optionalParams, MAX_STRING_LENGTH);
00092 ZeroMemory(newLauncherConfig->workspacePath, MAX_STRING_LENGTH);
00093 ZeroMemory(newLauncherConfig->vmParamter, MAX_STRING_LENGTH);
00094 ZeroMemory(newLauncherConfig->javaVM, MAX_STRING_LENGTH);
00095 }
00096
00097
00098
00099
00100
00101
00102
00103 void releaseLauncherConfig(LPLAUNCHERCONFIG launcherConfig)
00104 {
00105 free(launcherConfig->name);
00106 free(launcherConfig->executablePath);
00107 free(launcherConfig->optionalParams);
00108 free(launcherConfig->workspacePath);
00109 free(launcherConfig->vmParamter);
00110 free(launcherConfig->javaVM);
00111
00112 free(launcherConfig);
00113 }
00114
00115 TCHAR* getMeSomeMemory(int size)
00116 {
00117 TCHAR* buffer;
00118
00119 assert(size != 0);
00120
00121 buffer = (TCHAR*)malloc(size);
00122
00123 return(buffer);
00124 }
00125
00126 void giveTheMemoryBack(TCHAR* memoryBlock)
00127 {
00128 assert(memoryBlock != NULL);
00129
00130 free(memoryBlock);
00131 }
00132
00133 void setValue(TCHAR** member, TCHAR* value, int size)
00134 {
00135 assert(value != NULL);
00136 assert(size != 0);
00137
00138 if(*member == NULL)
00139 {
00140 *member = getMeSomeMemory(size);
00141 }
00142
00143 if(lstrlen(*member) < size)
00144 {
00145 giveTheMemoryBack(*member);
00146 *member = getMeSomeMemory(size);
00147 }
00148
00149 lstrcpyn(*member, value, size);
00150 }
00151
00152 void setName(LPLAUNCHERCONFIG launcherConfig, TCHAR* name, int size)
00153 {
00154 assert(launcherConfig != NULL);
00155 setValue(&(launcherConfig->name), name, size);
00156 }
00157
00158 void setExecutablePath(LPLAUNCHERCONFIG launcherConfig, TCHAR* executablePath, int size)
00159 {
00160 assert(launcherConfig != NULL);
00161 setValue(&(launcherConfig->executablePath), executablePath, size);
00162 }
00163
00164 void setWorkspacePath(LPLAUNCHERCONFIG launcherConfig, TCHAR* workspacePath, int size)
00165 {
00166 assert(launcherConfig != NULL);
00167 setValue(&(launcherConfig->workspacePath), workspacePath, size);
00168 }
00169
00170 void setOptionalParameter(LPLAUNCHERCONFIG launcherConfig, TCHAR* optionalParameter, int size)
00171 {
00172 assert(launcherConfig != NULL);
00173 setValue(&(launcherConfig->optionalParams), optionalParameter, size);
00174 }
00175
00176 void setVMParameter(LPLAUNCHERCONFIG launcherConfig, TCHAR* vmParameter, int size)
00177 {
00178 assert(launcherConfig != NULL);
00179 setValue(&(launcherConfig->vmParamter), vmParameter, size);
00180 }
00181
00182 void setJavaVM(LPLAUNCHERCONFIG launcherConfig, TCHAR* javaVM, int size)
00183 {
00184 assert(launcherConfig != NULL);
00185 setValue(&(launcherConfig->javaVM), javaVM, size);
00186 }
00187
00188 TCHAR* getName(LPLAUNCHERCONFIG launcherConfig)
00189 {
00190 assert(launcherConfig != NULL);
00191
00192 return (launcherConfig->name);
00193 }
00194
00195 TCHAR* getExecutablePath(LPLAUNCHERCONFIG launcherConfig)
00196 {
00197 assert(launcherConfig != NULL);
00198
00199 return (launcherConfig->executablePath);
00200 }
00201
00202 TCHAR* getWorkspacePath(LPLAUNCHERCONFIG launcherConfig)
00203 {
00204 assert(launcherConfig != NULL);
00205
00206 return (launcherConfig->workspacePath);
00207 }
00208
00209 TCHAR* getOptionalParameter(LPLAUNCHERCONFIG launcherConfig)
00210 {
00211 assert(launcherConfig != NULL);
00212
00213 return (launcherConfig->optionalParams);
00214 }
00215
00216 TCHAR* getVMParameter(LPLAUNCHERCONFIG launcherConfig)
00217 {
00218 assert(launcherConfig != NULL);
00219
00220 return (launcherConfig->vmParamter);
00221 }
00222
00223 TCHAR* getJavaVM(LPLAUNCHERCONFIG launcherConfig)
00224 {
00225 assert(launcherConfig != NULL);
00226
00227 return (launcherConfig->javaVM);
00228 }