Update contrib.
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // wins\specific\property.cpp
15 // Emulator property management for emulator settings
19 #define _CRTIMP // we want to use the static runtime library
21 #define __INCLUDE_CAPABILITY_NAMES__
28 #define _DUMP_PROPERTY
32 //SL: added this to support relative paths
36 #define GetCurrentDir _getcwd
37 #define FullPath _fullpath
40 #define GetCurrentDir getcwd
41 #define FullPath fullpath
46 const char* KDefaultMachineName = "epoc";
47 const char* KDefaultTestMachineName = "defaulttest";
49 // name of the environment variable to check for default path
50 const char* KDefaultEpocRootName = "EPOCROOT";
54 // At the point this is created there is no kernel heap available
55 // So all memory allocation is done from a custom allocator
57 const TInt KMaxTokenLength = 255;
61 enum {ETotalMemory=0x10000}; // 64K
64 TAny* Alloc(TInt aSize);
65 TAny* Realloc(TAny* aCell, TInt aSize);
66 void Free(TAny* aCell);
68 TUint iBuf[ETotalMemory];
72 Allocator::Allocator()
76 TAny* Allocator::Alloc(TInt aSize)
78 aSize = (aSize + 7) >> 2;
79 if (iFree + aSize > iBuf + ETotalMemory)
87 TAny* Allocator::Realloc(TAny* aCell, TInt aSize)
92 TUint* p = (TUint*)aCell;
94 if (iFree == p + size)
96 aSize = (aSize + 7) >> 2;
97 if (p + aSize > iBuf + ETotalMemory)
104 TAny* newp = Alloc(aSize);
107 memcpy(newp, aCell, size*sizeof(TUint));
113 void Allocator::Free(TAny* )
117 Allocator TheAllocator;
121 char* Duplicate(const char* aString)
126 TInt size = strlen(aString) + 1;
127 char* p = (char*)TheAllocator.Alloc(size);
129 memcpy(p, aString, size);
133 // Properties class implementation
135 Properties::Properties()
136 :iEntries(NULL),iCount(0),iSize(0)
139 const char* Properties::Insert(TInt aIndex, const char* aProperty, const char* aValue)
143 TInt size = iSize == 0 ? 8 : iSize*2;
144 TAny* array = TheAllocator.Realloc(iEntries, size*sizeof(SEntry));
147 iEntries = (SEntry*)array;
151 char* prop = Duplicate(aProperty);
154 char* value = Duplicate(aValue);
156 TheAllocator.Free(prop);
159 SEntry* e = &iEntries[aIndex];
160 memmove(e+1, e, (iCount-aIndex)*sizeof(SEntry));
168 const char* Properties::Replace(const char* aProperty, const char* aValue)
170 TInt ix = Find(aProperty);
172 return Insert(~ix, aProperty, aValue);
173 // replacing a property
174 SEntry& e = iEntries[ix];
175 char* value = Duplicate(aValue);
178 TheAllocator.Free(e.iValue);
184 const char* Properties::Append(const char* aProperty, const char* aValue)
186 TInt ix = Find(aProperty);
188 return Insert(~ix, aProperty, aValue);
191 SEntry& e = iEntries[ix];
192 TInt size = strlen(e.iValue) + strlen(aValue) + 2;
193 char* value = (char*)TheAllocator.Realloc(e.iValue, size);
197 strcat(value, aValue);
203 TInt Properties::GetString(const char* aProperty, const char*& aValue) const
205 TInt ix = Find(aProperty);
208 aValue = iEntries[ix].iValue;
212 TInt Properties::GetInt(const char* aProperty, TInt& aValue) const
214 TInt ix = Find(aProperty);
217 char* value = iEntries[ix].iValue;
219 TBool neg = *value=='-';
221 long val = strtoul(value, &end, 0);
234 TInt Properties::GetBool(const char* aProperty, TBool& aValue, TBool aDefaultValue) const
236 TInt ix = Find(aProperty);
239 aValue = aDefaultValue;
242 const char* value=iEntries[ix].iValue;
243 if (_stricmp(value, "on")==0 || _stricmp(value, "yes")==0 || _stricmp(value, "1")==0 || strlen(value)==0)
248 if (_stricmp(value, "off")==0 || _stricmp(value, "no")==0 || _stricmp(value, "0")==0 )
254 // Bool property has an illegal value!
258 TInt Properties::Find(const char* aProperty) const
260 // Lookup a property in the table
261 // return index (>=0) if found, ~insertion-point (<0) if not
264 TInt l = 0, r = iCount;
267 TInt m = (l + r) >> 1;
268 const SEntry& e = iEntries[m];
269 TInt k = _stricmp(aProperty,e.iProperty);
280 #ifdef _DUMP_PROPERTY
281 void Properties::Dump() const
283 for (TInt i = 0; i < iCount; ++i)
285 const SEntry& e = iEntries[i];
287 strcpy(buf, e.iProperty);
288 TInt len = strlen(e.iValue);
293 strcat(buf, e.iValue);
296 strncat(buf, e.iValue, 256);
301 OutputDebugStringA(buf);
306 // Property related variant functions
308 TInt Wins::EmulatorHal(TInt aFunction, TAny* a1, TAny* a2)
313 case EEmulatorHalStringProperty:
314 return iProperties.GetString((const char*)a1,*(const char**)a2);
315 case EEmulatorHalIntProperty:
316 return iProperties.GetInt((const char*)a1,*(TInt*)a2);
317 case EEmulatorHalBoolProperty:
318 return iProperties.GetBool((const char*)a1,*(TBool*)a2);
319 case EEmulatorHalMapFilename:
320 return MapFilename(*(const TDesC*)a1,*(TDes*)a2);
321 case EEmulatorHalSetFlip:
325 TInt screen = (TInt)a2;
326 if((TUint)screen < (TUint)iUi->NumberOfScreens())
327 return iUi->SetFlip(TEmulatorFlip(TInt(a1)),screen);
331 case EEmulatorHalColorDepth:
333 TUint colorDepth = KDefaultColorDepth;
336 if((TUint)a2 < (TUint)iUi->NumberOfScreens())
337 colorDepth = iUi->ColorDepth((TInt)a2);
339 *(TUint*)a1 = colorDepth;
342 case EEmulatorHalCPUSpeed:
344 return SetCpuSpeed(TUint(a2)/1000);
345 *(TInt*)a2 = iCpuSpeed ? iCpuSpeed * 1000 : 1;
347 case EEmulatorHalNumberOfScreens:
348 *(TInt*)a2 = iUi ? iUi->NumberOfScreens() : 1;
350 case EEmulatorHalSetDisplayChannel:
351 if (iUi && (TUint)a1 < (TUint)iUi->NumberOfScreens())
353 r = iUi->SetDisplayChannel((TInt)a1, static_cast<DDisplayChannel*>(a2));
357 r = KErrNotSupported;
367 const char* KExtensionListNormal = "btracex.ldd;hcr.dll;winsgui;elocd.ldd;medint.pdd;medlfs.pdd;medmmc.pdd;epbusmmc.dll;epbusv.dll";
368 const char* KExtensionUsiiNand = "?medusiiw.pdd";
369 const char* KExtensionUsiiNandLoader = "?medusiiws.pdd";
370 const char* KExtensionUsiiNandTest = "?medusiiwt.pdd";
375 const int KMaxEpocRootSize = 120;
377 TInt Wins::InitProperties(TBool aRunExe)
379 if (iProperties.Replace("MachineName", KDefaultMachineName) == NULL)
382 char epocRoot[KMaxEpocRootSize];
384 TInt total = GetEnvironmentVariableA( KDefaultEpocRootName, epocRoot, KMaxEpocRootSize);
388 if (iProperties.Replace("EpocRoot", epocRoot) == NULL)
392 if (iProperties.Append("Extension", KExtensionListNormal) == NULL)
395 char overrideCDrive[MAX_PATH];
396 overrideCDrive[0] = '\0';
397 TInt r = ProcessCommandLine(aRunExe, overrideCDrive);
405 r = LoadProperties();
409 // get Unistore II Media Driver type from epoc.ini
410 const char* value = NULL;
413 iProperties.GetString("NandDriverType", value);
416 if (value && _stricmp("XSR",value)==0)
418 // epoc.ini "NandDriverType=XSR" for XSR/Unistore-II driver
419 if (iProperties.Append("Extension", KExtensionUsiiNand) == NULL)
422 else if (value && _stricmp("XSRNandloader",value)==0)
424 // epoc.ini "NandDriverType=XSRNandloader" for XSR/Unistore-II nandloader driver
425 if (iProperties.Append("Extension", KExtensionUsiiNandLoader) == NULL)
428 else if (value && _stricmp("XSRTest",value)==0)
430 // epoc.ini "NandDriverType=XSRTest" for XSR/Unistore-II test driver
431 if (iProperties.Append("Extension", KExtensionUsiiNandTest) == NULL)
436 // If epoc.ini contains "NandDriverType=???" but ??? not equal to any
437 // of above XSR driver types then load production/release XSR
439 if (iProperties.Append("Extension", KExtensionUsiiNand) == NULL)
446 // Load the production/release XSR driver, if value is NULL
447 if (iProperties.Append("Extension", KExtensionUsiiNand) == NULL)
453 // load additional configuration specific properties
455 // get the multi property "configuration"
457 iProperties.GetString("configuration", value);
459 // load each one of these
460 // check for any screen specific properties in the main epoc.ini
461 // if configuration property is set
462 if (value && !iConfigPropertySet) //configuration
465 char configFileName[100];
468 //load each set of properties
470 const char * pdest = strchr(value, ';');
471 TInt result = pdest - value;
474 strncpy(configFileName, value, result);
475 configFileName[result] = '\0';
476 value = value + result + 1;
480 strcpy(configFileName, value);
481 value += strlen(value);
484 r = LoadConfigSpecificProperties(configFileName);
492 //if iConfigId is zero, there is only 1 configuration
493 wsprintfA(scr, "ConfigCount %d", iConfigId ? iConfigId : 1);
494 r = AddProperty(scr, scr+strlen(scr));
498 r = SetupMediaPath();
502 if (overrideCDrive[0] != '\0')
503 SetupDrive('c', overrideCDrive);
505 if (iProperties.Append("Extension", "exstart") == NULL)
508 #ifdef _DUMP_PROPERTY
515 char* skipws(char* aPtr)
517 while (isspace(*aPtr))
522 char* skiptok(char* aPtr)
527 while (*aPtr && *aPtr++ != '\"')
532 while (*aPtr && !isspace(*aPtr))
545 // Only the first 32 trace bits can be defined using these values
546 // "ALWAYS" in this context means all of the first 32 bits not all 256 bits
547 const TDebugTrace KTraceValues[] =
551 {"DEVICE", 1<<KDEVICE},
554 {"EVENT", 1<<KEVENT},
556 {"DEBUGGER", 1<<KDEBUGGER},
557 {"EXTENSION", 1<<KEXTENSION},
559 {"HARDWARE", 1<<KHARDWARE},
561 {"LOCDRV", 1<<KLOCDRV},
562 {"MEMTRACE", 1<<KMEMTRACE},
564 {"NKERN", 1<<KNKERN},
565 {"OBJECT", 1<<KOBJECT},
566 {"PANIC", 1<<KPANIC},
567 {"PBUS1", 1<<KPBUS1},
568 {"PBUS2", 1<<KPBUS2},
569 {"PBUSDRV", 1<<KPBUSDRV},
570 {"POWER", 1<<KPOWER},
572 {"SCHED", 1<<KSCHED},
573 {"SCHED2", 1<<KSCHED2},
574 {"SCRATCH", 1<<KSCRATCH},
575 {"SEMAPHORE", 1<<KSEMAPHORE},
576 {"SERVER", 1<<KSERVER},
577 {"THREAD", 1<<KTHREAD},
578 {"THREAD2", 1<<KTHREAD2},
579 {"TIMING", 1<<KTIMING},
583 const TInt KMaxTraceName = 9;
584 const TInt KCountTraceValues = sizeof(KTraceValues)/sizeof(TDebugTrace);
586 static const TDebugTrace* TraceType(const char* aTrace, TInt aLen)
588 if (aLen > KMaxTraceName)
591 char name[KMaxTraceName + 1];
592 strncpy(name, aTrace, aLen);
595 for (TInt i=KCountTraceValues; --i>=0;)
597 if (_stricmp(name, KTraceValues[i].iName)==0)
598 return &KTraceValues[i];
604 TInt Wins::DebugMask()
606 TInt mask = KDefaultDebugMask;
607 if (iProperties.GetInt("DebugMask", mask) != KErrArgument)
612 if (iProperties.GetString("DebugMask", e) != KErrNone)
617 char* p = skipws((char*)e);
629 const TDebugTrace* type = TraceType(p, e - p);
635 mask &= ~type->iMask;
642 TUint32 Wins::KernelConfigFlags()
648 iProperties.GetBool("PlatSecEnforcement",b,EFalse);
649 if(b) flags |= EKernelConfigPlatSecEnforcement;
650 Wins::EarlyLogging("PlatSecEnforcement ",b?"ON":"OFF");
653 iProperties.GetBool("PlatSecDiagnostics",b,EFalse);
654 if(b) flags |= EKernelConfigPlatSecDiagnostics;
655 Wins::EarlyLogging("PlatSecDiagnostics ",b?"ON":"OFF");
658 iProperties.GetBool("PlatSecProcessIsolation",b,EFalse);
659 if(b) flags |= EKernelConfigPlatSecProcessIsolation;
660 Wins::EarlyLogging("PlatSecProcessIsolation ",b?"ON":"OFF");
663 iProperties.GetBool("PlatSecEnforceSysBin",b,EFalse);
664 if(b) flags |= EKernelConfigPlatSecEnforceSysBin;
665 Wins::EarlyLogging("PlatSecEnforceSysBin ",b?"ON":"OFF");
668 iProperties.GetBool("CrazyScheduling",b,EFalse);
669 if(b) flags |= EKernelConfigCrazyScheduling;
670 Wins::EarlyLogging("CrazyScheduling ",b?"ON":"OFF");
675 void Wins::DisabledCapabilities(SCapabilitySet& aCapabilities)
678 if(iProperties.GetString("PlatSecDisabledCaps", text)!=KErrNone)
680 Wins::EarlyLogging("PlatSecDisabledCaps ",text);
681 ParseCapabilitiesArg(aCapabilities,text);
684 #define PARSE_CAPABILITIES_ERROR(aMessage) Wins::EarlyLogging(aMessage,0)
685 #define PARSE_CAPABILITIES_ERROR2(aMessage,aArg) Wins::EarlyLogging(aMessage,aArg)
686 #define strnicmp _strnicmp
688 TInt Wins::ParseCapabilitiesArg(SCapabilitySet& aCapabilities, const char *aText)
690 // This is a cun'n'paste copy of the function in TOOLS\E32TOOLS\HOST\H_UTIL.CPP
691 // Keep both of these versions up to date with each other
694 memset(&aCapabilities,0,sizeof(aCapabilities));
714 const char* name = aText;
715 while((c=*aText)>' ')
724 if(n==3 && strnicmp("all",name,n)==0)
728 PARSE_CAPABILITIES_ERROR("Capability '-ALL' not allowed");
731 for(i=0; i<ECapability_Limit; i++)
733 if(CapabilityNames[i])
734 aCapabilities[i>>5] |= (1<<(i&31));
739 if(n==4 && strnicmp("none",name,n)==0)
743 PARSE_CAPABILITIES_ERROR("Capability '-NONE' not allowed");
746 memset(&aCapabilities,0,sizeof(aCapabilities));
750 for(i=0; i<ECapability_Limit; i++)
752 const char* cap = CapabilityNames[i];
755 if((int)strlen(cap)!=n)
757 if(strnicmp(cap,name,n)!=0)
761 if(i>=ECapability_Limit)
764 if(n>=sizeof(badName)) n=sizeof(badName)-1;
765 memcpy(badName,name,n);
767 PARSE_CAPABILITIES_ERROR2("Unrecognised capability name: ",badName);
771 aCapabilities[i>>5] &= ~(1<<(i&31));
773 aCapabilities[i>>5] |= (1<<(i&31));
778 TInt Wins::AddProperty(char* aProperty, const char* aEol)
780 const char* tok = aProperty;
784 if (aProperty == aEol)
787 if (_stricmp(tok, "_NewScreen_") == 0)
794 char newtok[KMaxTokenLength];
795 if (ConfigSpecificProperty(tok))
797 wsprintfA(newtok, "Configuration[%d]", iConfigId);
802 return iProperties.Replace(tok, NULL) == NULL ? KErrNoMemory : KErrNone;
805 } while (isalnum(c) || c=='_');
806 aProperty[-1]='\0'; // terminate property name
815 else if (c=='+' && *aProperty=='=')
822 --aProperty; // point back to value
824 if (_strnicmp(tok, "_epoc_drive_", 12) == 0)
825 return SetupDrive(tok[12], aProperty);
828 char newtok[KMaxTokenLength];
829 if (ConfigSpecificProperty(tok))
831 if (ScreenSpecificProperty(tok))
833 wsprintfA(newtok, "Configuration[%d][%d]", iConfigId, ScreenId);
837 wsprintfA(newtok, "Configuration[%d]", iConfigId);
843 return iProperties.Append(tok, aProperty) == NULL ? KErrNoMemory : KErrNone;
845 return iProperties.Replace(tok, aProperty) == NULL ? KErrNoMemory : KErrNone;
849 TInt Wins::ProcessCommandLine(TBool aRunExe, char* aCDrive)
854 DWORD len=GetModuleFileNameA(NULL, exe, MAX_PATH);
858 const char* base = strrchr(exe, '\\') + 1;
859 if (iProperties.Replace("AutoRun", base) == NULL)
863 char* cmd = skipws(skiptok(GetCommandLineA()));
864 if (strstr(cmd, "--") != NULL)
868 cmd = strchr(cmd, '-') + 1;
872 char* end = skiptok(cmd);
874 switch (tolower(opt))
878 TInt r = AddProperty(cmd, end);
884 // specify base name for .INI file
885 if (iProperties.Replace("MachineName", cmd) == NULL)
890 if (iProperties.Replace("TheMachineLanguageIndex", cmd) == NULL)
894 // specify path for emulated C drive
896 DWORD len=GetFullPathNameA(cmd, MAX_PATH, aCDrive, NULL);
897 if (len==0 || len >= MAX_PATH)
902 // specify the temp path as the emulated C drive
904 DWORD len=GetTempPathA(MAX_PATH, aCDrive);
905 if (len==0 || len >= MAX_PATH)
915 if (aRunExe && iProperties.Replace("CommandLine", cmd) == NULL)
921 TInt Wins::LoadConfigSpecificProperties(const char * aFile)
924 TInt r = iProperties.GetString("EmulatorDataPath", path);
928 char file[KMaxFileName + 1];
933 r = ReadIniFile(file, iniData);
936 r = ReadProperties(iniData);
937 VirtualFree(iniData, 0, MEM_RELEASE);
939 else if (r == KErrNotFound)
948 TInt Wins::LoadProperties()
951 TInt r = iProperties.GetString("EmulatorDataPath", path);
955 r = iProperties.GetString("MachineName", name);
959 char file[KMaxFileName + 1];
962 strcat(file, ".ini");
965 r = ReadIniFile(file, iniData);
968 r = ReadProperties(iniData);
969 VirtualFree(iniData, 0, MEM_RELEASE);
971 else if (r == KErrNotFound)
973 if(_stricmp(name,KDefaultMachineName)==0)
976 name = KDefaultTestMachineName;
979 r = KErrNone; // no ini file - oh well
985 TInt Wins::ReadProperties(char* aData)
991 char* eol = strchr(beg, '\n');
995 if (eol[-1] == '\r' && --eol == beg)
997 *eol = '\0'; // terminate line
999 while (isspace(*beg))
1001 char* comment = strchr(beg, '#');
1004 while (eol > beg && isspace(eol[-1]))
1008 *eol = '\0'; // terminate line
1010 TInt r = AddProperty(beg, eol);
1015 wsprintfA(sc, "%d", ScreenId+1);
1017 if(iProperties.GetInt("[screens]", screens) == KErrNone && screens > ScreenId)
1020 return iProperties.Replace("[screens]", sc) == NULL ? KErrNoMemory : KErrNone;
1023 TInt Wins::ReadIniFile(const char* aFileName, char*& aContents)
1026 HANDLE file=CreateFileA(aFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1027 if (!file || file==INVALID_HANDLE_VALUE)
1028 r = KErrNotFound; // More than likely !
1031 TInt size=GetFileSize(file, NULL);
1032 if (size==INVALID_FILE_SIZE)
1036 // fileSize+3 to ensure zero-termination of file and trailing CRLF
1037 // VirtualAlloc initializes memory to zero
1038 TAny* data = VirtualAlloc(NULL, size+3, MEM_COMMIT, PAGE_READWRITE);
1044 if (!ReadFile(file, data, size, &bytesRead, NULL))
1046 VirtualFree(data, 0, MEM_RELEASE);
1051 aContents = (LPSTR)data;
1052 strcpy(aContents + size,"\r\n");
1062 TInt Wins::SetupPaths()
1064 // set up the Emulator paths
1067 // the Emulator path
1068 CHAR path[KMaxFileName + 1];
1069 DWORD len=GetModuleFileNameA(NULL, path, KMaxFileName);
1071 return(KErrGeneral);
1074 *(strrchr(path, '\\') + 1) = '\0';
1075 const char* emulatorPath = iProperties.Replace("EmulatorPath", path);
1077 return KErrNoMemory;
1079 CHAR drive[KMaxFileName + 1];
1081 // the Emulator data path
1082 strcat(path, "data\\");
1083 DWORD att = GetFileAttributesA(path);
1084 if (att != -1 && (att&FILE_ATTRIBUTE_DIRECTORY))
1086 // if Data directory exists in the emulator path, do things the new way
1087 strcpy(drive, emulatorPath);
1088 strcat(drive,"c\\");
1093 #if defined(__VC32__)
1094 char* p = strstr(path, "\\epoc32\\release\\wins\\");
1095 #elif defined(__CW32__)
1096 char* p = strstr(path, "\\epoc32\\release\\winscw\\");
1099 return KErrNotFound;
1100 strcpy(p, "\\epoc32\\");
1101 strcpy(drive, path);
1102 strcat(path, "data\\");
1103 #if defined(__VC32__)
1104 strcat(drive,"wins\\c\\");
1105 #elif defined(__CW32__)
1106 strcat(drive,"winscw\\c\\");
1109 if (!iProperties.Replace("EmulatorDataPath", path))
1110 return KErrNoMemory;
1112 // The Emulator Image path (for temporary EXE files)
1114 TInt r = iProperties.GetString("EmulatorImagePath", eip);
1117 len=GetTempPathA(KMaxFileName, path);
1118 strcat(path, "epoc\\");
1119 char* p = path + strlen(path);
1120 *p++ = emulatorPath[0];
1121 strcpy(p, emulatorPath+2);
1122 if (!iProperties.Replace("EmulatorImagePath", path))
1123 return KErrNoMemory;
1127 if (!Emulator::CreateAllDirectories(path))
1128 return Emulator::LastError();
1130 // Win32 filesystem paths mapped to local WINS drives
1131 r = SetupDrive('c',drive); // set up C here, can be overridden by system.ini settings
1135 strcpy(drive, emulatorPath);
1136 strcat(drive,"z\\");
1138 r=SetupDrive('z',drive); // set up Z here, can be overridden by system.ini settings
1145 TInt Wins::SetupMediaPath()
1147 // Set up the path for emulated media devices 'EmulatedMediaPath'
1148 // The default is <datapath>media/
1149 // The system temporary path can be set by value '%temp%'
1152 CHAR path[KMaxFileName + 1];
1154 if (iProperties.GetString("EmulatorMediaPath", mpath) == KErrNotFound)
1157 TInt r = iProperties.GetString("EmulatorDataPath", dpath);
1160 strcpy(path, dpath);
1161 strcat(path, "media\\");
1162 return iProperties.Replace("EmulatorMediaPath", path) ? KErrNone : KErrNoMemory;
1165 if (_stricmp(mpath, "%temp%") == 0)
1167 DWORD len=GetTempPathA(KMaxFileName, path);
1168 if (len > 0 && len < KMaxFileName)
1169 return iProperties.Replace("EmulatorMediaPath", path) ? KErrNone : KErrNoMemory;
1175 const char* Wins::EmulatorMediaPath()
1177 const char* mpath = NULL;
1178 iProperties.GetString("EmulatorMediaPath", mpath);
1183 TInt Wins::SetupDrive(int aDrive, const char* aPath)
1185 // set up emulated drives
1189 // Z drive can't end in anything but "Z\\", since we chop this off and use
1190 // the resulting directory to find filenames with no drive specified in
1191 // MapFileName() below.
1192 aDrive = tolower(aDrive);
1195 const char* end = aPath + strlen(aPath);
1196 if (_stricmp(end-2,"\\z") != 0 && _stricmp(end-3,"\\z\\") != 0)
1197 return KErrArgument;
1200 char prop[] = "_epoc_drive_?";
1201 *strchr(prop, '?') = char(aDrive);
1204 // If the path begins with the keyword %epocroot%, replace this with EPOCROOT
1205 if (_strnicmp(aPath, "%epocroot%", 10) == 0)
1207 aPath += 10; // skip "%epocroot%"
1210 TInt r = iProperties.GetString("EpocRoot", eRoot);
1214 int rootSize = strlen(eRoot);
1215 int pathSize = strlen(aPath);
1216 if(rootSize+pathSize>MAX_PATH)
1217 return KErrArgument;
1219 char fullPath[MAX_PATH+1];
1220 memcpy(fullPath,eRoot,rootSize);
1221 memcpy(fullPath+rootSize,aPath,pathSize+1); // +1 to get the terminating NULL char
1223 return iProperties.Replace(prop, fullPath) ? KErrNone : KErrNoMemory;
1228 //Otherwise aPath is potentially a relative path
1229 char path[FILENAME_MAX+1];
1230 //Resolve relative path
1231 FullPath(path,aPath,sizeof(path)/sizeof(char));
1232 //Now path is fully qualified path name. Use that.
1233 return iProperties.Replace(prop, path) ? KErrNone : KErrNoMemory;
1239 TInt Wins::MapDrive(int aDrive, TDes& aBuffer) const
1241 // Map aDrive to a path given by environment variables or defaults
1242 // Use this function only in WINS builds
1245 char drive[KMaxFileName + 1];
1246 char prop[] = "_epoc_drive_?";
1247 *strchr(prop, '?') = char(tolower(aDrive));
1251 if (iProperties.GetString(prop, val) == KErrNone)
1254 if (len > KMaxFileName)
1255 return KErrArgument;
1260 // not in properties, so check environment
1261 len = GetEnvironmentVariableA(prop, drive, KMaxFileName + 1);
1262 if (len > KMaxFileName)
1263 return KErrArgument;
1265 while (len > 0 && isspace(drive[len-1]))
1268 return KErrNotFound;
1269 if (drive[len-1] != '\\') // add trailing backslash
1270 drive[len++] = '\\';
1271 if (drive[0] == '\\')
1273 // put in the emulator drive
1274 TInt r = iProperties.GetString("EmulatorPath", val);
1278 memmove(drive + 2, drive, len);
1283 else if (len < 3 || drive[1] != ':' || drive[2] != '\\')
1284 return KErrArgument;
1286 TUint16* aBufPtr = (TUint16*)aBuffer.Ptr();
1287 const TText* drv = (const TText*)drive;
1288 for(int index=0;index<len;index++)
1289 *aBufPtr++ = (TUint16)*drv++;
1290 aBuffer.SetLength(len<<1);
1292 aBuffer.Copy(TPtrC8((const TText8*)drive,len));
1297 TInt Wins::MapFilename(const TDesC& aFilename, TDes& aBuffer) const
1299 // Map aFileName to real windows directory - aFileName must be a full filepath
1303 // if the filename does not have a drive specified then don't imagine
1304 // it describes an Epoc filepath
1305 // Assume it's a subdirectory/file of the file containing the emulated Z drive
1307 if (aFilename.Length() < 4 || aFilename[2] != ':')
1309 TInt r = MapDrive('z', aBuffer);
1312 aBuffer.SetLength(aBuffer.Length()-4); // chop "Z\\"
1313 offset = aFilename[0] == '\\' ? 1 : 0; // remove the guaranteed backslash
1317 TInt r = MapDrive(aFilename[0], aBuffer);
1320 if (aFilename.Length() >= 6 && aFilename[4] == '\\')
1327 TUint8* ptrFilename = (TUint8*)aFilename.Ptr() + offset;
1328 TUint8* ptrBuffer = (TUint8*)aBuffer.Ptr()+aBuffer.Length();
1329 if (aBuffer.MaxLength()<aBuffer.Length()+aFilename.Length()-offset+1)
1332 memcpy(ptrBuffer, ptrFilename, aFilename.Length()-offset);
1333 aBuffer.SetLength(aBuffer.Length()+aFilename.Length()-offset);
1335 TPtrC name(aFilename.Mid(offset));
1336 if (aBuffer.MaxLength()<aBuffer.Length()+name.Length()+1)
1338 aBuffer.Append(name);
1344 //table of the property names which can be used in multiple configurations
1345 const char * KConfigSpecificProperties[] =
1349 "PhysicalScreenWidth",
1350 "PhysicalScreenHeight",
1354 "LedArrangeVertically",
1355 "LedArrangeHorizontally",
1377 "EmulatorControlHotKey",
1378 "CompositionBuffers",
1382 const char * KScreenSpecificProperties[] =
1386 "PhysicalScreenWidth",
1387 "PhysicalScreenHeight",
1392 "CompositionBuffers",
1397 TBool Wins::ConfigSpecificProperty(const char * aProperty)
1400 TInt count = sizeof(KConfigSpecificProperties) / sizeof(char *);
1401 for (x = 0; x < count; ++x)
1402 if (_stricmp(aProperty, KConfigSpecificProperties[x]) == 0) return ETrue;
1406 TBool Wins::ScreenSpecificProperty(const char * aProperty)
1409 TInt count = sizeof(KScreenSpecificProperties) / sizeof(char *);
1410 for (x = 0; x < count; ++x)
1411 if (_stricmp(aProperty, KScreenSpecificProperties[x]) == 0) return ETrue;