bool MyGetLogicalDriveStrings(UStringVector &driveStrings) { driveStrings.Clear(); if (g_IsNT) { UINT32 size = GetLogicalDriveStringsW(0, NULL); if (size == 0) return false; UString buffer; UINT32 newSize = GetLogicalDriveStringsW(size, buffer.GetBuffer(size)); if (newSize == 0) return false; if (newSize > size) return false; UString string; for (UINT32 i = 0; i < newSize; i++) { WCHAR c = buffer[i]; if (c == L'\0') { driveStrings.Add(string); string.Empty(); } else string += c; } return string.IsEmpty(); } CSysStringVector driveStringsA; bool res = MyGetLogicalDriveStrings(driveStringsA); for (int i = 0; i < driveStringsA.Size(); i++) driveStrings.Add(GetUnicodeString(driveStringsA[i])); return res; }
void CBrowseDialog::SetFilter(const UString &s) { Filters.Clear(); UString mask; unsigned i; for (i = 0; i < s.Len(); i++) { wchar_t c = s[i]; if (c == ';') { if (!mask.IsEmpty()) Filters.Add(mask); mask.Empty(); } else mask += c; } if (!mask.IsEmpty()) Filters.Add(mask); ShowAllFiles = Filters.IsEmpty(); for (i = 0; i < Filters.Size(); i++) { const UString &f = Filters[i]; if (f == L"*.*" || f == L"*") { ShowAllFiles = true; break; } } }
LONG CKey::GetValue_Strings(LPCTSTR valueName, UStringVector &strings) { strings.Clear(); CByteBuffer buffer; UInt32 dataSize; LONG res = QueryValue(valueName, buffer, dataSize); if (res != ERROR_SUCCESS) return res; if (dataSize % sizeof(wchar_t) != 0) return E_FAIL; const wchar_t *data = (const wchar_t *)(const Byte *)buffer; unsigned numChars = dataSize / sizeof(wchar_t); UString s; for (unsigned i = 0; i < numChars; i++) { wchar_t c = data[i]; if (c == 0) { strings.Add(s); s.Empty(); } else s += c; } return res; }
static HRESULT CreateMap(const UStringVector &names, const UString &id, CFileMapping &fileMapping, NSynchronization::CManualResetEvent &event, UString ¶ms) { UInt32 extraSize = 2; UInt32 dataSize = 0; for (int i = 0; i < names.Size(); i++) dataSize += (names[i].Length() + 1) * sizeof(wchar_t); UInt32 totalSize = extraSize + dataSize; UString mappingName; CRandom random; random.Init(GetTickCount()); for (;;) { int number = random.Generate(); wchar_t temp[32]; ConvertUInt64ToString(UInt32(number), temp); mappingName = id; mappingName += L"Mapping"; mappingName += temp; if (!fileMapping.Create(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, totalSize, GetSystemString(mappingName))) return E_FAIL; if (::GetLastError() != ERROR_ALREADY_EXISTS) break; fileMapping.Close(); } UString eventName; RINOK(CreateTempEvent(id + L"MappingEndEvent", event, eventName)); params += mappingName; params += L":"; wchar_t string[10]; ConvertUInt64ToString(totalSize, string); params += string; params += L":"; params += eventName; LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_WRITE, 0, totalSize); if (data == NULL) return E_FAIL; { wchar_t *curData = (wchar_t *)data; *curData = 0; curData++; for (int i = 0; i < names.Size(); i++) { const UString &s = names[i]; memcpy(curData, (const wchar_t *)s, s.Length() * sizeof(wchar_t)); curData += s.Length(); *curData++ = L'\0'; } } return S_OK; }
void CProxyArc2::GetDirPathParts(int dirIndex, UStringVector &pathParts, bool &isAltStreamDir) const { pathParts.Clear(); isAltStreamDir = false; if (dirIndex == k_Proxy2_RootDirIndex) return; if (dirIndex == k_Proxy2_AltRootDirIndex) { isAltStreamDir = true; return; } while (dirIndex >= k_Proxy2_NumRootDirs) { const CProxyDir2 &dir = Dirs[dirIndex]; const CProxyFile2 &file = Files[dir.ArcIndex]; if (pathParts.IsEmpty() && dirIndex == file.AltDirIndex) isAltStreamDir = true; pathParts.Insert(0, file.Name); int par = file.Parent; if (par < 0) break; dirIndex = Files[par].DirIndex; } }
void EnumerateDirItems( const UString &baseFolderPrefix, // base (disk) prefix for scanning const UStringVector &fileNames, // names relative to baseFolderPrefix const UString &archiveNamePrefix, CObjectVector<CDirItem> &dirItems, UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes) { for(int i = 0; i < fileNames.Size(); i++) { const UString &fileName = fileNames[i]; NFind::CFileInfoW fileInfo; if (!NFind::FindFile(baseFolderPrefix + fileName, fileInfo)) { errorCodes.Add(::GetLastError()); errorPaths.Add(baseFolderPrefix + fileName); continue; } AddDirFileInfo(archiveNamePrefix, fileName, fileInfo, dirItems); if (fileInfo.IsDirectory()) { EnumerateDirectory(baseFolderPrefix, fileName + wchar_t(kDirDelimiter), archiveNamePrefix + fileInfo.Name + wchar_t(kDirDelimiter), dirItems, errorPaths, errorCodes); } } }
static HRESULT EnumerateAltStreams( const NFind::CFileInfo &fi, const NWildcard::CCensorNode &curNode, int phyParent, int logParent, const FString &fullPath, const UStringVector &addArchivePrefix, // prefix from curNode CDirItems &dirItems) { NFind::CStreamEnumerator enumerator(fullPath); for (;;) { NFind::CStreamInfo si; bool found; if (!enumerator.Next(si, found)) { return dirItems.AddError(fullPath + FTEXT(":*")); // , (DWORD)E_FAIL } if (!found) return S_OK; if (si.IsMainStream()) continue; UStringVector addArchivePrefixNew = addArchivePrefix; UString reducedName = si.GetReducedName(); addArchivePrefixNew.Back() += reducedName; if (curNode.CheckPathToRoot(false, addArchivePrefixNew, true)) continue; NFind::CFileInfo fi2 = fi; fi2.Name += us2fs(reducedName); fi2.Size = si.Size; fi2.Attrib &= ~FILE_ATTRIBUTE_DIRECTORY; fi2.IsAltStream = true; dirItems.AddDirFileInfo(phyParent, logParent, -1, fi2); } }
static UString GetIconPath(const UString &filePath, const CLSID &clsID, const UString &extension, Int32 &iconIndex) { CPluginLibrary library; CMyComPtr<IFolderManager> folderManager; CMyComPtr<IFolderFolder> folder; if (filePath.IsEmpty()) folderManager = new CArchiveFolderManager; else if (library.LoadAndCreateManager(filePath, clsID, &folderManager) != S_OK) return UString(); CMyComBSTR extBSTR; if (folderManager->GetExtensions(&extBSTR) != S_OK) return UString(); const UString ext2 = (const wchar_t *)extBSTR; UStringVector exts; SplitString(ext2, exts); for (int i = 0; i < exts.Size(); i++) { const UString &plugExt = exts[i]; if (extension.CompareNoCase((const wchar_t *)plugExt) == 0) { CMyComBSTR iconPathTemp; if (folderManager->GetIconPath(plugExt, &iconPathTemp, &iconIndex) != S_OK) break; if (iconPathTemp != 0) return (const wchar_t *)iconPathTemp; } } return UString(); }
void AddUniqueString(UStringVector &list, const UString &s) { for (int i = 0; i < list.Size(); i++) if (s.CompareNoCase(list[i]) == 0) return; list.Add(s); }
int CPlugin::SetDirectory(const char *aszDir, int /* opMode */) { UString path = MultiByteToUnicodeString(aszDir, CP_OEMCP); if (path == WSTRING_PATH_SEPARATOR) { _folder.Release(); m_ArchiveHandler->BindToRootFolder(&_folder); } else if (path == L"..") { CMyComPtr<IFolderFolder> newFolder; _folder->BindToParentFolder(&newFolder); if (newFolder == NULL) throw 40312; _folder = newFolder; } else if (path.IsEmpty()) EnterToDirectory(path); else { if (path[0] == WCHAR_PATH_SEPARATOR) { _folder.Release(); m_ArchiveHandler->BindToRootFolder(&_folder); path = path.Mid(1); } UStringVector pathParts; SplitPathToParts(path, pathParts); for (int i = 0; i < pathParts.Size(); i++) EnterToDirectory(pathParts[i]); } GetCurrentDir(); return TRUE; }
void CContentsView::AddToArchive() { CRecordVector<UInt32> indices; GetOperatedItemIndices(indices); if (!Is_IO_FS_Folder()) { MessageBoxErrorLang(IDS_OPERATION_IS_NOT_SUPPORTED); return; } if (indices.Size() == 0) { MessageBoxErrorLang(IDS_SELECT_FILES); return; } UStringVector names; const UString curPrefix = GetFsPath(); UString destCurDirPrefix = curPrefix; if (IsFSDrivesFolder()) destCurDirPrefix = ROOT_FS_FOLDER; FOR_VECTOR (i, indices) names.Add(curPrefix + GetItemRelPath2(indices[i])); bool fromPrev = (names.Size() > 1); const UString arcName = CreateArchiveName(names.Front(), fromPrev, false); HRESULT res = CompressFiles(destCurDirPrefix, arcName, L"", true, // addExtension names, false, true, false); if (res != S_OK) { if (destCurDirPrefix.Len() >= MAX_PATH) MessageBoxErrorLang(IDS_MESSAGE_UNSUPPORTED_OPERATION_FOR_LONG_PATH_FOLDER); } // KillSelection(); }
void CDirItems::EnumerateDirItems2(const UString &phyPrefix, const UString &logPrefix, const UStringVector &filePaths, UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes) { int phyParent = phyPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, phyPrefix); int logParent = logPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, logPrefix); for (int i = 0; i < filePaths.Size(); i++) { const UString &filePath = filePaths[i]; NFind::CFileInfoW fi; const UString phyPath = phyPrefix + filePath; if (!fi.Find(phyPath)) { errorCodes.Add(::GetLastError()); errorPaths.Add(phyPath); continue; } int delimiter = filePath.ReverseFind((wchar_t)kDirDelimiter); UString phyPrefixCur; int phyParentCur = phyParent; if (delimiter >= 0) { phyPrefixCur = filePath.Left(delimiter + 1); phyParentCur = AddPrefix(phyParent, logParent, phyPrefixCur); } AddDirFileInfo(phyParentCur, logParent, fi, Items); if (fi.IsDir()) { const UString name2 = fi.Name + (wchar_t)kDirDelimiter; int parent = AddPrefix(phyParentCur, logParent, name2); EnumerateDirectory(parent, parent, phyPrefix + phyPrefixCur + name2, errorPaths, errorCodes); } } ReserveDown(); }
void CPanel::GetSelectedNames(UStringVector &selectedNames) { CRecordVector<UInt32> indices; GetSelectedItemsIndices(indices); selectedNames.ClearAndReserve(indices.Size()); FOR_VECTOR (i, indices) selectedNames.AddInReserved(GetItemRelPath(indices[i])); /* for (int i = 0; i < _listView.GetItemCount(); i++) { const int kSize = 1024; WCHAR name[kSize + 1]; LVITEMW item; item.iItem = i; item.pszText = name; item.cchTextMax = kSize; item.iSubItem = 0; item.mask = LVIF_TEXT | LVIF_PARAM; if (!_listView.GetItem(&item)) continue; int realIndex = GetRealIndex(item); if (realIndex == kParentIndex) continue; if (_selectedStatusVector[realIndex]) selectedNames.Add(item.pszText); } */ selectedNames.Sort(); }
void CCodecIcons::LoadIcons(HMODULE m) { UString iconTypes = MyLoadStringW(m, kIconTypesResId); UStringVector pairs; SplitString(iconTypes, pairs); for (int i = 0; i < pairs.Size(); i++) { const UString &s = pairs[i]; int pos = s.Find(L':'); CIconPair iconPair; iconPair.IconIndex = -1; if (pos < 0) pos = s.Length(); else { UString num = s.Mid(pos + 1); if (!num.IsEmpty()) { const wchar_t *end; iconPair.IconIndex = (UInt32)ConvertStringToUInt64(num, &end); if (*end != L'\0') continue; } } iconPair.Ext = s.Left(pos); IconPairs.Add(iconPair); } }
void CExtDatabase::Read() { CObjectVector<CExtInfo> extItems; ReadInternalAssociations(extItems); ReadFileFolderPluginInfoList(Plugins); for (int i = 0; i < extItems.Size(); i++) { const CExtInfo &extInfo = extItems[i]; CExtInfoBig extInfoBig; extInfoBig.Ext = extInfo.Ext; extInfoBig.Associated = false; for (int p = 0; p < extInfo.Plugins.Size(); p++) { int pluginIndex = FindPlugin(extInfo.Plugins[p]); if (pluginIndex >= 0) extInfoBig.PluginsPairs.Add(CPluginEnabledPair(pluginIndex, true)); } ExtBigItems.Add(extInfoBig); } for (int pluginIndex = 0; pluginIndex < Plugins.Size(); pluginIndex++) { const CPluginInfo &pluginInfo = Plugins[pluginIndex]; CPluginLibrary pluginLibrary; CMyComPtr<IFolderManager> folderManager; if (pluginInfo.FilePath.IsEmpty()) folderManager = new CArchiveFolderManager; else if (pluginLibrary.LoadAndCreateManager(pluginInfo.FilePath, pluginInfo.ClassID, &folderManager) != S_OK) continue; CMyComBSTR extBSTR; if (folderManager->GetExtensions(&extBSTR) != S_OK) return; const UString ext2 = (const wchar_t *)extBSTR; UStringVector exts; SplitString(ext2, exts); for (int i = 0; i < exts.Size(); i++) { const UString &ext = exts[i]; int index = FindExtInfoBig(ext); if (index < 0) { CExtInfoBig extInfo; extInfo.PluginsPairs.Add(CPluginEnabledPair(pluginIndex, false)); extInfo.Associated = false; extInfo.Ext = ext; ExtBigItems.Add(extInfo); } else { CExtInfoBig &extInfo = ExtBigItems[index]; int pluginIndexIndex = extInfo.FindPlugin(pluginIndex); if (pluginIndexIndex < 0) extInfo.PluginsPairs.Add(CPluginEnabledPair(pluginIndex, false)); } } } }
void CDrop::QueryFileNames(UStringVector &fileNames) { fileNames.Clear(); UINT numFiles = QueryCountOfFiles(); fileNames.Reserve(numFiles); for(UINT i = 0; i < numFiles; i++) fileNames.Add(QueryFileName(i)); }
HRESULT CThreadCopyFrom::ProcessVirt() { UStringVector fileNames; CRecordVector<const wchar_t *> fileNamePointers; fileNames.Add(Name); fileNamePointers.Add(fileNames[0]); return FolderOperations->CopyFrom(PathPrefix, &fileNamePointers.Front(), fileNamePointers.Size(), UpdateCallback); };
void zmodifyer::del( UStringVector & file_names, wchar_t const * password ) { UStringVector commandStrings; commandStrings.Add( L"D" ); update( file_names, commandStrings, password ); }
HRESULT CPanel::CopyFrom(bool moveMode, const UString &folderPrefix, const UStringVector &filePaths, bool showErrorMessages, UStringVector *messages) { CMyComPtr<IFolderOperations> folderOperations; _folder.QueryInterface(IID_IFolderOperations, &folderOperations); HRESULT res; if (!folderOperations) res = E_NOINTERFACE; else { CThreadUpdate updater; updater.MoveMode = moveMode; updater.UpdateCallbackSpec = new CUpdateCallback100Imp; updater.UpdateCallback = updater.UpdateCallbackSpec; updater.UpdateCallbackSpec->ProgressDialog = &updater.ProgressDialog; UString title = LangString(IDS_COPYING); UString progressWindowTitle = L"7-Zip"; // LangString(IDS_APP_TITLE); updater.ProgressDialog.MainWindow = GetParent(); updater.ProgressDialog.MainTitle = progressWindowTitle; updater.ProgressDialog.MainAddTitle = title + UString(L' '); updater.UpdateCallbackSpec->Init(false, L""); updater.FolderOperations = folderOperations; updater.FolderPrefix = folderPrefix; updater.FileNames.ClearAndReserve(filePaths.Size()); unsigned i; for (i = 0; i < filePaths.Size(); i++) updater.FileNames.AddInReserved(filePaths[i]); updater.FileNamePointers.ClearAndReserve(updater.FileNames.Size()); for (i = 0; i < updater.FileNames.Size(); i++) updater.FileNamePointers.AddInReserved(updater.FileNames[i]); NWindows::CThread thread; RINOK(thread.Create(CThreadUpdate::MyThreadFunction, &updater)); updater.ProgressDialog.Create(title, thread, GetParent()); if (messages != 0) *messages = updater.ProgressDialog.Sync.Messages; res = updater.Result; } if (res == E_NOINTERFACE) { UString errorMessage = LangString(IDS_OPERATION_IS_NOT_SUPPORTED); if (showErrorMessages) MessageBox(errorMessage); else if (messages != 0) messages->Add(errorMessage); return E_ABORT; } RefreshTitleAlways(); return res; }
void AddUniqueStringToHeadOfList(UStringVector &list, const UString &s) { for (unsigned i = 0; i < list.Size();) if (s.IsEqualTo_NoCase(list[i])) list.Delete(i); else i++; list.Insert(0, s); }
static void AddToCensorFromListFile(NWildcard::CCensor &wildcardCensor, LPCWSTR fileName, bool include, NRecursedType::EEnum type, UINT codePage) { UStringVector names; if (!ReadNamesFromListFile(fileName, names, codePage)) throw kIncorrectListFile; for (int i = 0; i < names.Size(); i++) AddNameToCensor(wildcardCensor, names[i], include, type); }
void SortStrings(const UStringVector &src, UStringVector &dest) { CIntVector indices; SortStringsToIndices(src, indices); dest.Clear(); dest.Reserve(indices.Size()); for (int i = 0; i < indices.Size(); i++) dest.Add(src[indices[i]]); }
static void GetArguments(int numArguments, const char *arguments[], UStringVector &parts) { parts.Clear(); for(int i = 0; i < numArguments; i++) { UString s = MultiByteToUnicodeString(arguments[i]); parts.Add(s); } }
void mySplitCommandLine(int numArguments,const char *arguments[],UStringVector &parts) { { // define P7ZIP_HOME_DIR static char p7zip_home_dir[MAX_PATH]; AString dir,name; my_windows_split_path(arguments[0],dir,name); snprintf(p7zip_home_dir,sizeof(p7zip_home_dir),"P7ZIP_HOME_DIR=%s/",(const char *)dir); p7zip_home_dir[sizeof(p7zip_home_dir)-1] = 0; putenv(p7zip_home_dir); } #ifdef ENV_HAVE_LOCALE // set the program's current locale from the user's environment variables setlocale(LC_ALL,""); // auto-detect which conversion p7zip should use char *locale = setlocale(LC_CTYPE,0); if (locale) { size_t len = strlen(locale); char *locale_upper = (char *)malloc(len+1); if (locale_upper) { strcpy(locale_upper,locale); for(size_t i=0;i<len;i++) locale_upper[i] = toupper(locale_upper[i] & 255); if ( (strcmp(locale_upper,"") != 0) && (strcmp(locale_upper,"C") != 0) && (strcmp(locale_upper,"POSIX") != 0) ) { global_use_utf16_conversion = 1; } free(locale_upper); } } #elif defined(LOCALE_IS_UTF8) global_use_utf16_conversion = 1; // assume LC_CTYPE="utf8" #else global_use_utf16_conversion = 0; // assume LC_CTYPE="C" #endif parts.Clear(); for(int ind=0;ind < numArguments; ind++) { if ((ind <= 2) && (strcmp(arguments[ind],"-no-utf16") == 0)) { global_use_utf16_conversion = 0; } else if ((ind <= 2) && (strcmp(arguments[ind],"-utf16") == 0)) { global_use_utf16_conversion = 1; } else { UString tmp = MultiByteToUnicodeString(arguments[ind]); // tmp.Trim(); " " is a valid filename ... if (!tmp.IsEmpty()) { parts.Add(tmp); } } } }
void CProxyFolder::GetPathParts(UStringVector &pathParts) const { pathParts.Clear(); const CProxyFolder *current = this; while (current->Parent != NULL) { pathParts.Insert(0, current->Name); current = current->Parent; } }
void CPlugin::GetCurrentDir() { m_CurrentDir.Empty(); UStringVector pathParts; GetPathParts(pathParts); for (int i = 0; i < pathParts.Size(); i++) { m_CurrentDir += WCHAR_PATH_SEPARATOR; m_CurrentDir += pathParts[i]; } }
void mySplitCommandLineW(int numArguments, TCHAR **arguments,UStringVector &parts) { parts.Clear(); for(int ind=0;ind < numArguments; ind++) { UString tmp = arguments[ind]; // tmp.Trim(); " " is a valid filename ... if (!tmp.IsEmpty()) { parts.Add(tmp); } } }
void MakeCorrectPath(UStringVector &pathParts) { for (int i = 0; i < pathParts.Size();) { UString &s = pathParts[i]; s = GetCorrectFileName(s); if (s.IsEmpty()) pathParts.Delete(i); else i++; } }
void mySplitCommandLineW(int numArguments, TCHAR **arguments,UStringVector &parts) { parts.Clear(); for(int ind=0;ind < numArguments; ind++) { UString tmp = arguments[ind]; // tmp.Trim(); " " is a valid filename ... if (!tmp.IsEmpty()) { parts.Add(tmp); // DEBUG printf("ARG %d : '%ls'\n",ind,(const wchar_t *)tmp); } } }
void CProxyArc::GetDirPathParts(int dirIndex, UStringVector &pathParts) const { pathParts.Clear(); while (dirIndex >= 0) { const CProxyDir &dir = Dirs[dirIndex]; dirIndex = dir.ParentDir; if (dirIndex < 0) break; pathParts.Insert(0, dir.Name); } }