bool DeleteDirectory(const UnicodeString & ADirName) { TSearchRecChecked SearchRec; bool retval = true; if (::FindFirst(ADirName + L"\\*", faAnyFile, SearchRec) == 0) // VCL Function { if (FLAGSET(SearchRec.Attr, faDirectory)) { if ((SearchRec.Name != THISDIRECTORY) && (SearchRec.Name != PARENTDIRECTORY)) retval = DeleteDirectory(ADirName + L"\\" + SearchRec.Name); } else { retval = ::DeleteFile(ApiPath(ADirName + L"\\" + SearchRec.Name)); } if (retval) { while (FindNextChecked(SearchRec) == 0) { // VCL Function if (FLAGSET(SearchRec.Attr, faDirectory)) { if ((SearchRec.Name != THISDIRECTORY) && (SearchRec.Name != PARENTDIRECTORY)) retval = DeleteDirectory(ADirName + L"\\" + SearchRec.Name); } else { retval = ::DeleteFile(ApiPath(ADirName + L"\\" + SearchRec.Name)); } if (!retval) { break; } } } } FindClose(SearchRec); if (retval) { retval = ::RemoveDir(ADirName); // VCL function } return retval; }
//--------------------------------------------------------------------------- TStrings * __fastcall TGUIConfiguration::GetLocales() { UnicodeString LocalesExts; TStringList * Exts = new TStringList(); try { Exts->Sorted = true; Exts->CaseSensitive = false; int FindAttrs = faReadOnly | faArchive; TSearchRec SearchRec; bool Found; Found = (bool)(FindFirst(ChangeFileExt(ModuleFileName(), L".*"), FindAttrs, SearchRec) == 0); try { UnicodeString Ext; while (Found) { Ext = ExtractFileExt(SearchRec.Name).UpperCase(); if ((Ext.Length() >= 3) && (Ext != L".EXE") && (Ext != L".COM") && (Ext != L".DLL") && (Ext != L".INI")) { Ext = Ext.SubString(2, Ext.Length() - 1); LocalesExts += Ext; Exts->Add(Ext); } Found = (FindNextChecked(SearchRec) == 0); } } __finally { FindClose(SearchRec); } if (FLastLocalesExts != LocalesExts) { FLastLocalesExts = LocalesExts; FLocales->Clear(); TLanguages * Langs = Languages(); int Ext, Index, Count; wchar_t LocaleStr[255]; LCID Locale; Count = Langs->Count; Index = -1; while (Index < Count) { if (Index >= 0) { Locale = Langs->LocaleID[Index]; Ext = Exts->IndexOf(Langs->Ext[Index]); if (Ext < 0) { Ext = Exts->IndexOf(Langs->Ext[Index].SubString(1, 2)); if (Ext >= 0) { Locale = MAKELANGID(PRIMARYLANGID(Locale), SUBLANG_DEFAULT); } } if (Ext >= 0) { Exts->Objects[Ext] = reinterpret_cast<TObject*>(Locale); } else { Locale = 0; } } else { Locale = InternalLocale(); } if (Locale) { UnicodeString Name; GetLocaleInfo(Locale, LOCALE_SENGLANGUAGE, LocaleStr, LENOF(LocaleStr)); Name = LocaleStr; Name += L" - "; // LOCALE_SNATIVELANGNAME GetLocaleInfo(Locale, LOCALE_SLANGUAGE, LocaleStr, LENOF(LocaleStr)); Name += LocaleStr; FLocales->AddObject(Name, reinterpret_cast<TObject*>(Locale)); } Index++; } for (int Index = 0; Index < Exts->Count; Index++) { if ((Exts->Objects[Index] == NULL) && (Exts->Strings[Index].Length() == 3) && SameText(Exts->Strings[Index].SubString(1, 2), AdditionaLanguagePrefix)) { UnicodeString LangName = GetFileFileInfoString(L"LangName", ChangeFileExt(ModuleFileName(), UnicodeString(L".") + Exts->Strings[Index])); if (!LangName.IsEmpty()) { FLocales->AddObject(LangName, reinterpret_cast<TObject*>( AdditionaLanguageMask + Exts->Strings[Index][3])); } } } } } __finally { delete Exts; } return FLocales; }