Ignore:
Timestamp:
Jul 13, 2017, 5:17:57 AM (8 years ago)
Author:
stevenhl
Message:

Import modifications from cwmm-0_2_9-work-01_10_2006.zip dated 2006-08-27

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mediafolder/c/createcd/createcd.c

    r2 r4  
    11/*
    2  * This file is (C) Chris Wohlgemuth 1999-2002
     2 * This file is (C) Chris Wohlgemuth 1999-2005
    33 */
    44/*
     
    2929#include <string.h>
    3030#include "mediafolderinc.h"
     31#include "mediafolderres.h"
     32/* #include "sys_funcs.h" */
    3133
    3234#define  LVM_IS_HARDDISK  0 
     
    9294PFNVIR pfnvirGet_Volume_Information=NULLHANDLE;
    9395
    94 BOOL loadLVMFuncs(void)
     96size_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 */
     103static 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 */
     150static 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 
     226static BOOL loadLVMFuncs(void)
    95227{
    96228  char chrErrorObject[CCHMAXPATH]={0};
     
    173305}
    174306
    175 int main(void)
     307int main(int argc, char** argv)
    176308{
    177309  CARDINAL32 error;
    178310  int iNumCD;
    179311  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];
    183316  int a;
     317  HMODULE hmodRes=NULLHANDLE;
    184318
    185319  if(!CDQueryCDDrives(&iNumCD, &cFirst))
    186320    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));
    187326
    188327  if(!loadLVMFuncs()) {
     
    190329      int b;
    191330      /* Build folder name */
    192       sprintf(name, "CD-Audio^Drive %c:", cFirst+a);
     331      sprintf(name, nameTemplate, cFirst+a);
    193332      /* Build object ID */
    194333      sprintf(id, CDFLDR_ID, cFirst+a);
     
    231370
    232371              /* Build folder name */
    233               sprintf(name, "CD-Audio^Drive %c:", vir.Current_Drive_Letter);
     372              sprintf(name, nameTemplate, vir.Current_Drive_Letter);
    234373              /* Build object ID */
    235374              sprintf(id, CDFLDR_ID, vir.Current_Drive_Letter);
     
    242381                if(WinCreateObject(CDFLDR_CLASSNAME, name, setup, CDFLDR_LOCATION, CO_UPDATEIFEXISTS))
    243382                  break;
    244 
    245383                //      printf("Found:  %s, %s\n", name, setup);
    246384                DosSleep(5000);
     
    255393    DosFreeModule(hMod);
    256394  } /* else */
     395  if(hmodRes)
     396    DosFreeModule(hmodRes);
    257397  return (0);
    258398}
    259399
    260400
     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 */
     426static size_t
     427strlcpy(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.