Changeset 4 for trunk/mediafolder/c/createcd
- Timestamp:
- Jul 13, 2017, 5:17:57 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mediafolder/c/createcd/createcd.c
r2 r4 1 1 /* 2 * This file is (C) Chris Wohlgemuth 1999-200 22 * This file is (C) Chris Wohlgemuth 1999-2005 3 3 */ 4 4 /* … … 29 29 #include <string.h> 30 30 #include "mediafolderinc.h" 31 #include "mediafolderres.h" 32 /* #include "sys_funcs.h" */ 31 33 32 34 #define LVM_IS_HARDDISK 0 … … 92 94 PFNVIR pfnvirGet_Volume_Information=NULLHANDLE; 93 95 94 BOOL loadLVMFuncs(void) 96 size_t strlcpy(char *dst, const char *src, size_t siz); 97 98 /* 99 FIXME: 100 101 Use the function from the \common_funcs directory instead. 102 */ 103 static BOOL getMessage(char* text,ULONG ulID, LONG lSizeText, HMODULE hResource) 104 { 105 char* pOffset; 106 char* ptr; 107 int id=0; 108 109 text[0]='\0'; 110 111 // printf("resource: %x, %d %d\n", hResource, ulID, (ulID/16)+1, 112 // DosGetResource(hResource, RT_STRING, (ulID/16)+1, (PVOID)&pOffset)); 113 114 if(DosGetResource(hResource, RT_STRING, (ulID/16)+1, (PVOID)&pOffset)!=NO_ERROR) 115 return FALSE; 116 117 ptr=pOffset; 118 119 //printf("\ngot resource...\n"); 120 121 /* Parsing... */ 122 id=ulID%16; 123 124 //printf("id: %d\n", id); 125 pOffset+=sizeof(USHORT); /* Skip codepage */ 126 127 for(;id > 0;id--) 128 { 129 //printf("id: %d, length: %d %s\n", id, *pOffset, pOffset+1); 130 pOffset+=*pOffset+1; 131 } 132 //printf("length: %d %s\n", *pOffset, pOffset+1); 133 strlcpy(text, pOffset+1, lSizeText); 134 135 if(*pOffset!=1){ 136 DosFreeResource(ptr); 137 return TRUE; 138 } 139 DosFreeResource(ptr); 140 /* Length=1 means dummy entry filled by system */ 141 return FALSE; 142 } 143 144 #if 0 145 #pragma import(DosQueryModFromEIP,,"DOSCALL1",360) 146 APIRET APIENTRY DosQueryModFromEIP ( HMODULE *phMod, ULONG *pObjNum, ULONG BuffLen, PCHAR pBuff, ULONG *pOffset, PVOID Address ) ; 147 #endif 148 149 /* This function returns the module handle of our ressource dll */ 150 static HMODULE queryResModuleHandle(void) 151 { 152 char path[CCHMAXPATH]; 153 char buf[CCHMAXPATH]; 154 char* found; 155 APIRET rc; 156 HMODULE RESSOURCEHANDLE; 157 HMODULE hmod; 158 PTIB ptib = NULL; 159 PPIB ppib = NULL; 160 161 162 // printf("rc=%d\n",DosQueryModFromEIP( &hmod, &ul, sizeof(path), path, 163 // &off, (PVOID)queryResModuleHandle ) ); 164 if(NO_ERROR==DosGetInfoBlocks(&ptib, &ppib)) 165 DosQueryModuleName (ppib->pib_hmte, /* Module handle to query */ 166 sizeof(path), /* Maximum length of result */ 167 path); 168 169 //printf("%s %x\n",path, hmod); 170 171 /* Get the language code of our system and load the 172 resource DLL with the right language */ 173 do 174 { 175 static char chrLang[]="en_EN"; 176 PSZ pszLang=""; 177 char *chrPtr; 178 179 /* Get Language var */ 180 if(NO_ERROR!=DosScanEnv("LANG", &pszLang)) { 181 pszLang=chrLang; 182 } 183 /* Skip leading spaces */ 184 chrPtr=pszLang; 185 while(*chrPtr==' ') 186 chrPtr++; 187 188 /* Check if value seems to be valid. The var must be something like xx_XX thus length is 5 */ 189 if(strlen(chrPtr)<5) 190 break; 191 192 if((found=strrchr(path, '\\'))!=NULLHANDLE) 193 *found=0; 194 195 /* Extract the first two chars and build DLL name */ 196 sprintf(buf, RESDLLNAME, chrPtr[0], chrPtr[1]); 197 strcat(path,buf); 198 199 rc=DosLoadModule(buf,sizeof(buf),path, &RESSOURCEHANDLE); 200 if(rc==NO_ERROR) 201 break; 202 203 /* NLS DLL not found. Try to load default */ 204 found=strrchr(path,'\\'); 205 if(!found) 206 break; 207 208 *found=0; 209 sprintf(buf, DEFRESDLLNAME); 210 strcat(path,buf); 211 212 rc=DosLoadModule(buf,sizeof(buf),path, &RESSOURCEHANDLE); 213 if(rc!=NO_ERROR) { 214 RESSOURCEHANDLE=NULLHANDLE; 215 } 216 else { 217 // printf("Ressource DLL loaded.\n"); 218 } 219 break; 220 }while(TRUE); 221 222 return RESSOURCEHANDLE; 223 } 224 225 226 static BOOL loadLVMFuncs(void) 95 227 { 96 228 char chrErrorObject[CCHMAXPATH]={0}; … … 173 305 } 174 306 175 int main( void)307 int main(int argc, char** argv) 176 308 { 177 309 CARDINAL32 error; 178 310 int iNumCD; 179 311 char cFirst; 180 char setup[100]; 181 char name[100]; 182 char id[40]; 312 char setup[512]; 313 char name[256]; 314 char id[100]; 315 char nameTemplate[256]; 183 316 int a; 317 HMODULE hmodRes=NULLHANDLE; 184 318 185 319 if(!CDQueryCDDrives(&iNumCD, &cFirst)) 186 320 exit(1); 321 322 hmodRes=queryResModuleHandle(); 323 324 if(!getMessage(nameTemplate, /* IDSTR_LAUNCHPADFLYOVER */ IDSTR_CDFOLDERNAME, sizeof(nameTemplate), hmodRes)) 325 strncpy(nameTemplate, "CD-Audio player^Drive %c:", sizeof(nameTemplate)); 187 326 188 327 if(!loadLVMFuncs()) { … … 190 329 int b; 191 330 /* Build folder name */ 192 sprintf(name, "CD-Audio^Drive %c:", cFirst+a);331 sprintf(name, nameTemplate, cFirst+a); 193 332 /* Build object ID */ 194 333 sprintf(id, CDFLDR_ID, cFirst+a); … … 231 370 232 371 /* Build folder name */ 233 sprintf(name, "CD-Audio^Drive %c:", vir.Current_Drive_Letter);372 sprintf(name, nameTemplate, vir.Current_Drive_Letter); 234 373 /* Build object ID */ 235 374 sprintf(id, CDFLDR_ID, vir.Current_Drive_Letter); … … 242 381 if(WinCreateObject(CDFLDR_CLASSNAME, name, setup, CDFLDR_LOCATION, CO_UPDATEIFEXISTS)) 243 382 break; 244 245 383 // printf("Found: %s, %s\n", name, setup); 246 384 DosSleep(5000); … … 255 393 DosFreeModule(hMod); 256 394 } /* else */ 395 if(hmodRes) 396 DosFreeModule(hmodRes); 257 397 return (0); 258 398 } 259 399 260 400 401 /********************************************************************/ 402 /* $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $ */ 403 404 /* 405 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> 406 * 407 * Permission to use, copy, modify, and distribute this software for any 408 * purpose with or without fee is hereby granted, provided that the above 409 * copyright notice and this permission notice appear in all copies. 410 * 411 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 412 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 413 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 414 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 415 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 416 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 417 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 418 */ 419 420 421 /* 422 * Copy src to string dst of size siz. At most siz-1 characters 423 * will be copied. Always NUL terminates (unless siz == 0). 424 * Returns strlen(src); if retval >= siz, truncation occurred. 425 */ 426 static size_t 427 strlcpy(char *dst, const char *src, size_t siz) 428 { 429 register char *d = dst; 430 register const char *s = src; 431 register size_t n = siz; 432 433 /* Copy as many bytes as will fit */ 434 if (n != 0 && --n != 0) { 435 do { 436 if ((*d++ = *s++) == 0) 437 break; 438 } while (--n != 0); 439 } 440 441 /* Not enough room in dst, add NUL and traverse rest of src */ 442 if (n == 0) { 443 if (siz != 0) 444 *d = '\0'; /* NUL-terminate dst */ 445 while (*s++) 446 ; 447 } 448 449 return(s - src - 1); /* count does not include NUL */ 450 } 451
Note:
See TracChangeset
for help on using the changeset viewer.