bool VDRegistryKey::getString(const char *pszName, VDStringW& str) const { if (!pHandle) return false; if (GetVersion() & 0x80000000) { VDStringA v; if (!getString(pszName, v)) return false; str = VDTextAToW(v); return true; } const VDStringW wsName(VDTextAToW(pszName)); DWORD type, s = sizeof(DWORD); if (!pHandle || RegQueryValueExW((HKEY)pHandle, wsName.c_str(), 0, &type, NULL, &s) || type != REG_SZ) return false; if (s <= 0) str.clear(); else { str.resize((s + sizeof(wchar_t) - 1) / sizeof(wchar_t)); if (RegQueryValueExW((HKEY)pHandle, wsName.c_str(), 0, NULL, (BYTE *)&str[0], &s)) return false; str.resize(wcslen(str.c_str())); // Trim off pesky terminating NULLs. } return true; }
void tool_lookup(const vdfastvector<const char *>& args, const vdfastvector<const char *>& switches, bool amd64) { if (args.size() < 2) help_lookup(); char *s; sint64 addr = _strtoi64(args[1], &s, 16); if (*s) fail("lookup: invalid address \"%s\"", args[0]); vdautoptr<IVDSymbolSource> pss(VDCreateSymbolSourceLinkMap()); pss->Init(VDTextAToW(args[0]).c_str()); const VDSymbol *sym = pss->LookupSymbol(addr); if (!sym) fail("symbol not found for address %08x", addr); const char *fn; int line; if (pss->LookupLine(addr, fn, line)) printf("%08I64x %s + %x [%s:%d]\n", addr, sym->name, addr-sym->rva, fn, line); else printf("%08I64x %s + %x\n", addr, sym->name, addr-sym->rva); }
void VDDialogEditAccelerators::BoundCommand::GetText(int subItem, VDStringW& s) const { if (subItem == 0) { s = VDTextAToW(mpCommand); } else if (subItem == 1) { VDUIGetAcceleratorString(mAccel, s); } }
VDStringW VDGetLocalAppDataPath() { int csidl = CSIDL_APPDATA; HMODULE hmodShell32 = VDLoadSystemLibraryW32("shell32"); if (hmodShell32) { typedef HRESULT (CALLBACK *tpDllGetVersion)(DLLVERSIONINFO *); DLLVERSIONINFO dvi = {sizeof(DLLVERSIONINFO)}; tpDllGetVersion pDllGetVersion = (tpDllGetVersion)GetProcAddress(hmodShell32, "DllGetVersion"); if (pDllGetVersion && NOERROR == pDllGetVersion(&dvi)) { if (dvi.dwMajorVersion >= 5) csidl = CSIDL_LOCAL_APPDATA; } FreeLibrary(hmodShell32); } if (VDIsWindowsNT()) { wchar_t pathW[MAX_PATH]; if (!SHGetSpecialFolderPathW(NULL, pathW, csidl, FALSE)) return VDGetProgramPath(); return VDStringW(pathW); } else { char pathA[MAX_PATH]; if (!SHGetSpecialFolderPathA(NULL, pathA, csidl, FALSE)) return VDGetProgramPath(); return VDTextAToW(pathA); } }
VDStringW VDGetSystemPath9x() { char path[MAX_PATH]; if (!GetSystemDirectoryA(path, MAX_PATH)) throw MyWin32Error("Cannot locate system directory: %%s", GetLastError()); return VDTextAToW(path); }
void VDGetRootPaths(vdvector<VDStringW>& paths) { union { WCHAR w[512]; CHAR a[1024]; } buf; if (VDIsWindowsNT()) { vdfastvector<WCHAR> heapbufw; WCHAR *pw = buf.w; DWORD wlen = vdcountof(buf.w); for(;;) { *pw = 0; DWORD r = GetLogicalDriveStringsW(wlen, pw); if (!r) return; if (r <= wlen) break; heapbufw.resize(r); wlen = r; pw = heapbufw.data(); } while(*pw) { paths.push_back() = pw; pw += wcslen(pw) + 1; } } else { vdfastvector<CHAR> heapbufa; CHAR *pa = buf.a; DWORD alen = vdcountof(buf.a); for(;;) { *pa = 0; DWORD r = GetLogicalDriveStringsA(alen, pa); if (!r) return; if (r <= alen) break; heapbufa.resize(r); alen = r; pa = heapbufa.data(); } while(*pa) { paths.push_back() = VDTextAToW(pa); pa += strlen(pa) + 1; } } }
VDStringW VDGetFullPath(const wchar_t *partialPath) { static tpGetFullPathNameW spGetFullPathNameW = (tpGetFullPathNameW)GetProcAddress(GetModuleHandle("kernel32.dll"), "GetFullPathNameW"); union { char a[MAX_PATH]; wchar_t w[MAX_PATH]; } tmpBuf; if (spGetFullPathNameW && !(GetVersion() & 0x80000000)) { LPWSTR p; tmpBuf.w[0] = 0; DWORD count = spGetFullPathNameW(partialPath, MAX_PATH, tmpBuf.w, &p); if (count < MAX_PATH) return VDStringW(tmpBuf.w); VDStringW tmp(count); DWORD newCount = spGetFullPathNameW(partialPath, count, (wchar_t *)tmp.data(), &p); if (newCount < count) return tmp; return VDStringW(partialPath); } else { LPSTR p; VDStringA pathA(VDTextWToA(partialPath)); tmpBuf.a[0] = 0; DWORD count = GetFullPathNameA(pathA.c_str(), MAX_PATH, tmpBuf.a, &p); if (count < MAX_PATH) return VDStringW(VDTextAToW(tmpBuf.a)); VDStringA tmpA(count); DWORD newCount = GetFullPathNameA(pathA.c_str(), count, (char *)tmpA.data(), &p); if (newCount < count) return VDTextAToW(tmpA); return VDStringW(partialPath); } }
VDStringW VDGetWindowTextW32(HWND hwnd) { union { wchar_t w[256]; char a[512]; } buf; if (VDIsWindowsNT()) { int len = GetWindowTextLengthW(hwnd); if (len > 255) { vdblock<wchar_t> tmp(len + 1); len = GetWindowTextW(hwnd, tmp.data(), tmp.size()); VDStringW text(tmp.data(), len); return text; } else if (len > 0) { len = GetWindowTextW(hwnd, buf.w, 256); VDStringW text(buf.w, len); return text; } } else { int len = GetWindowTextLengthA(hwnd); if (len > 511) { vdblock<char> tmp(len + 1); len = GetWindowTextA(hwnd, tmp.data(), tmp.size()); VDStringW text(VDTextAToW(tmp.data(), len)); return text; } else if (len > 0) { len = GetWindowTextA(hwnd, buf.a, 512); VDStringW text(VDTextAToW(buf.a, len)); return text; } } return VDStringW(); }
VDStringW VDGetLongPathA(const wchar_t *s) { const VDStringA& pathA = VDTextWToA(s); CHAR buf[MAX_PATH]; DWORD len = GetLongPathNameA(pathA.c_str(), buf, MAX_PATH); VDStringW longPath; if (!len) longPath = s; else if (len <= MAX_PATH) longPath = VDTextAToW(buf); else if (len > MAX_PATH) { vdfastvector<CHAR> extbuf(len, 0); DWORD len2 = GetLongPathNameA(pathA.c_str(), extbuf.data(), len); if (len2 && len2 <= len) longPath = VDTextAToW(extbuf.data()); else longPath = s; } return longPath; }
bool VDRegistryKey::setString(const char *pszName, const wchar_t *pszString) const { if (pHandle) { if (GetVersion() & 0x80000000) { VDStringA s(VDTextWToA(pszString)); if (RegSetValueEx((HKEY)pHandle, pszName, 0, REG_SZ, (const BYTE *)s.data(), s.size())) return true; } else { if (RegSetValueExW((HKEY)pHandle, VDTextAToW(pszName).c_str(), 0, REG_SZ, (const BYTE *)pszString, sizeof(wchar_t) * wcslen(pszString))) return true; } } return false; }
bool VDDirectoryIterator::Next() { if (mbSearchComplete) return false; union { WIN32_FIND_DATAA a; WIN32_FIND_DATAW w; } wfd; uint32 attribs; if (GetVersion() & 0x80000000) { if (mpHandle) mbSearchComplete = !FindNextFileA((HANDLE)mpHandle, &wfd.a); else { mpHandle = FindFirstFileA(VDTextWToA(mSearchPath).c_str(), &wfd.a); mbSearchComplete = (INVALID_HANDLE_VALUE == mpHandle); } if (mbSearchComplete) return false; mbDirectory = (wfd.a.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; mFilename = VDTextAToW(wfd.a.cFileName); mFileSize = wfd.a.nFileSizeLow + ((sint64)wfd.w.nFileSizeHigh << 32); mLastWriteDate.mTicks = wfd.a.ftLastWriteTime.dwLowDateTime + ((uint64)wfd.a.ftLastWriteTime.dwHighDateTime << 32); attribs = wfd.a.dwFileAttributes; } else { if (mpHandle) mbSearchComplete = !FindNextFileW((HANDLE)mpHandle, &wfd.w); else { mpHandle = FindFirstFileW(mSearchPath.c_str(), &wfd.w); mbSearchComplete = (INVALID_HANDLE_VALUE == mpHandle); } if (mbSearchComplete) return false; mbDirectory = (wfd.w.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; mFilename = wfd.w.cFileName; mFileSize = wfd.w.nFileSizeLow + ((sint64)wfd.w.nFileSizeHigh << 32); mLastWriteDate.mTicks = wfd.w.ftLastWriteTime.dwLowDateTime + ((uint64)wfd.w.ftLastWriteTime.dwHighDateTime << 32); attribs = wfd.w.dwFileAttributes; } mAttributes = VDFileGetAttributesFromNativeW32(attribs); return true; }
void VDDialogEditAccelerators::RefilterCommands(const char *pattern) { mFilteredCommands.clear(); LBClear(IDC_AVAILCOMMANDS); Commands::const_iterator it(mAllCommands.begin()), itEnd(mAllCommands.end()); for(; it != itEnd; ++it) { const VDAccelToCommandEntry& ent = **it; if (VDFileWildMatch(pattern, ent.mpName)) { const VDStringW s(VDTextAToW(ent.mpName)); mFilteredCommands.push_back(&ent); LBAddString(IDC_AVAILCOMMANDS, s.c_str()); } } LBSetSelectedIndex(IDC_AVAILCOMMANDS, 0); }
VDStringW VDGetMenuItemTextByCommandW32(HMENU hmenu, UINT cmd) { VDStringW s; if (VDIsWindowsNT()) { MENUITEMINFOW mmiW; vdfastfixedvector<wchar_t, 256> bufW; mmiW.cbSize = MENUITEMINFO_SIZE_VERSION_400W; mmiW.fMask = MIIM_TYPE; mmiW.fType = MFT_STRING; mmiW.dwTypeData = NULL; mmiW.cch = 0; // required to avoid crash on NT4 if (GetMenuItemInfoW(hmenu, cmd, FALSE, &mmiW)) { bufW.resize(mmiW.cch + 1, 0); ++mmiW.cch; mmiW.dwTypeData = bufW.data(); if (GetMenuItemInfoW(hmenu, cmd, FALSE, &mmiW)) s = bufW.data(); } } else { MENUITEMINFOA mmiA; vdfastfixedvector<char, 256> bufA; mmiA.cbSize = MENUITEMINFO_SIZE_VERSION_400A; mmiA.fMask = MIIM_TYPE; mmiA.fType = MFT_STRING; mmiA.dwTypeData = NULL; if (GetMenuItemInfoA(hmenu, cmd, FALSE, &mmiA)) { bufA.resize(mmiA.cch + 1, 0); ++mmiA.cch; mmiA.dwTypeData = bufA.data(); if (GetMenuItemInfoA(hmenu, cmd, FALSE, &mmiA)) s = VDTextAToW(bufA.data()); } } return s; }
VDStringW VDGetRootVolumeLabel(const wchar_t *rootPath) { union { char a[MAX_PATH * 2]; wchar_t w[MAX_PATH]; } buf; DWORD maxComponentLength; DWORD fsFlags; VDStringW name; if (VDIsWindowsNT()) { if (GetVolumeInformationW(rootPath, buf.w, vdcountof(buf.w), NULL, &maxComponentLength, &fsFlags, NULL, 0)) name = buf.w; } else { if (GetVolumeInformationA(VDTextWToA(rootPath).c_str(), buf.a, vdcountof(buf.a), NULL, &maxComponentLength, &fsFlags, NULL, 0)) name = VDTextAToW(buf.a); } return name; }
void tool_resextract(const std::vector<const char *>& args, const std::vector<const char *>& switches, bool amd64) { if (args.size() != 2) { printf("usage: resextract <exe-name> <output file>\n"); exit(5); } const char *exename = args[0]; const char *outfile = args[1]; VDTextOutputFile out(VDTextAToW(outfile).c_str()); HMODULE hmod = LoadLibraryEx(exename, NULL, LOAD_LIBRARY_AS_DATAFILE); if (!hmod) throw MyWin32Error("Cannot load executable module \"%s\": %%s", GetLastError(), exename); EnumResourceTypes(hmod, EnumResTypesCB, (LONG_PTR)&out); FreeLibrary(hmod); }
VDStringW VDGetProgramFilePath() { union { wchar_t w[MAX_PATH]; char a[MAX_PATH]; } buf; VDStringW wstr; if (VDIsWindowsNT()) { if (!GetModuleFileNameW(NULL, buf.w, MAX_PATH)) throw MyWin32Error("Unable to get program path: %%s", GetLastError()); wstr = buf.w; } else { if (GetModuleFileNameA(NULL, buf.a, MAX_PATH)) throw MyWin32Error("Unable to get program path: %%s", GetLastError()); wstr = VDTextAToW(buf.a, -1); } return wstr; }
void VDUIDialogPlugins::FilterItem::GetText(int subItem, VDStringW& s) const { switch(subItem) { case 0: { VDExternalModule *module = mpFDI->GetModule(); if (module) s = VDFileSplitPath(module->GetFilename().c_str()); else s = L"(internal)"; } break; case 1: s = L"Video filter"; break; case 2: s = VDTextAToW(mpFDI->GetName()); break; } }
void VDDumpChangeLog() { HRSRC hResource = FindResource(NULL, MAKEINTRESOURCE(IDR_CHANGES), "STUFF"); if (!hResource) return; HGLOBAL hGlobal = LoadResource(NULL, hResource); if (!hGlobal) return; LPVOID lpData = LockResource(hGlobal); if (!lpData) return; const char *s = (const char *)lpData; while(*s!='\r') ++s; s+=2; tTextStream lineBuffer; VDStringA breakLineBuffer; bool foundNonIndentedLine = false; while(*s) { // parse line if (*s != ' ') { if (foundNonIndentedLine) break; foundNonIndentedLine = true; } const char *end = s; while(*end && *end != '\r' && *end != '\n') ++end; lineBuffer.clear(); append_cooked(lineBuffer, s, end, false); // skip line termination s = end; if (*s == '\r' || *s == '\n') { ++s; if ((s[0] ^ s[-1]) == ('\r' ^ '\n')) ++s; } lineBuffer.push_back(0); // break into lines const char *t = lineBuffer.data(); int maxLine = 78; breakLineBuffer.clear(); do { const char *lineStart = t; const char *break1 = NULL; const char *break2 = NULL; do { while(*t && *t != ' ') ++t; const char *u = t; while(*t && *t == ' ') ++t; if (u - lineStart > maxLine) { if (!break1) { break1 = u + maxLine; break2 = break1; } break; } break1 = u; break2 = t; } while(*t); breakLineBuffer.append(lineStart, break1); VDLog(kVDLogInfo, VDTextAToW(breakLineBuffer.data(), breakLineBuffer.size())); t = break2; breakLineBuffer.clear(); breakLineBuffer.resize(5, ' '); maxLine = 73; } while(*t); } }
bool VDAudioOutputWaveOutW32::Init(uint32 bufsize, uint32 bufcount, const WAVEFORMATEX *wf, const wchar_t *preferredDevice) { UINT deviceID = WAVE_MAPPER; if (preferredDevice && *preferredDevice) { UINT numDevices = waveOutGetNumDevs(); for(UINT i=0; i<numDevices; ++i) { WAVEOUTCAPSA caps = {0}; if (MMSYSERR_NOERROR == waveOutGetDevCapsA(i, &caps, sizeof(caps))) { const VDStringW key(VDTextAToW(caps.szPname).c_str()); if (key == preferredDevice) { deviceID = i; break; } } } } mBuffer.resize(bufsize * bufcount); mBlockHead = 0; mBlockTail = 0; mBlockWriteOffset = 0; mBlocksPending = 0; mBlockSize = bufsize; mBlockCount = bufcount; mBytesQueued = 0; if (!mhWaveEvent) { mhWaveEvent = CreateEvent(NULL, FALSE, FALSE, NULL); if (!mhWaveEvent) return false; } MMRESULT res = waveOutOpen(&mhWaveOut, deviceID, wf, (DWORD_PTR)mhWaveEvent, 0, CALLBACK_EVENT); if (MMSYSERR_NOERROR != res) { Shutdown(); return false; } mCurState = kStateOpened; mSamplesPerSec = wf->nSamplesPerSec; mAvgBytesPerSec = wf->nAvgBytesPerSec; // Hmmm... we can't allocate buffers while the wave device // is active... mHeaders.resize(bufcount); memset(mHeaders.data(), 0, bufcount * sizeof mHeaders[0]); for(uint32 i=0; i<bufcount; ++i) { WAVEHDR& hdr = mHeaders[i]; hdr.dwBufferLength = bufsize; hdr.dwBytesRecorded = 0; hdr.dwFlags = 0; hdr.dwLoops = 0; hdr.dwUser = 0; hdr.lpData = mBuffer.data() + bufsize * i; res = waveOutPrepareHeader(mhWaveOut, &hdr, sizeof hdr); if (MMSYSERR_NOERROR != res) { Shutdown(); return false; } } waveOutPause(mhWaveOut); return true; }
void AppendAVIAutoscan(const wchar_t *pszFile) { wchar_t buf[MAX_PATH]; wchar_t *s = buf, *t; int count = 0; if (!inputAVI) return; IVDStreamSource *pVSS = inputVideo->asStream(); VDPosition originalCount = pVSS->getEnd(); wcscpy(buf, pszFile); t = VDFileSplitExt(VDFileSplitPath(s)); if (t>buf) --t; try { for(;;) { if (!VDDoesPathExist(buf)) break; if (!inputAVI->Append(buf)) break; ++count; s = t; for(;;) { if (s<buf || !isdigit(*s)) { memmove(s+2, s+1, sizeof(wchar_t) * wcslen(s)); s[1] = L'1'; ++t; } else { if (*s == L'9') { *s-- = L'0'; continue; } ++*s; } break; } } } catch(const MyError& e) { // if the first segment failed, turn the warning into an error if (!count) throw; // log append errors, but otherwise eat them VDLog(kVDLogWarning, VDTextAToW(e.gets())); } guiSetStatus("Appended %d segments (stopped at \"%s\")", 255, count, VDTextWToA(buf).c_str()); if (count) { FrameSubset& s = g_project->GetTimeline().GetSubset(); g_project->BeginTimelineUpdate(); s.insert(s.end(), FrameSubsetNode(originalCount, pVSS->getEnd() - originalCount, false, 0)); g_project->EndTimelineUpdate(); } }
int wmain(int argc, wchar_t **argv) { _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF); wprintf(L"VirtualDub test harness utility for " BUILD L"\n"); wprintf(L"Copyright (C) 2005-2008 Avery Lee. Licensed under GNU General Public License\n\n"); Tests selectedTests; if (argc <= 1) { help(); exit(0); } else { for(int i=1; i<argc; ++i) { const wchar_t *test = argv[i]; if (!_wcsicmp(test, L"all")) { for(Tests::const_iterator it(g_tests.begin()), itEnd(g_tests.end()); it!=itEnd; ++it) { const TestInfo& ent = *it; if (ent.mbAutoRun) selectedTests.push_back(ent); } break; } for(Tests::const_iterator it(g_tests.begin()), itEnd(g_tests.end()); it!=itEnd; ++it) { const TestInfo& ent = *it; if (!_wcsicmp(VDTextAToW(ent.mpName).c_str(), test)) { selectedTests.push_back(ent); goto next; } } wprintf(L"\nUnknown test: %ls\n", test); help(); exit(5); next: ; } } long exts = CPUCheckForExtensions(); int failedTests = 0; for(;;) { CPUEnableExtensions(exts); wprintf(L"Setting CPU extensions: %08x\n", exts); for(Tests::const_iterator it(selectedTests.begin()), itEnd(selectedTests.end()); it!=itEnd; ++it) { const Tests::value_type& ent = *it; wprintf(L"Running test: %hs\n", ent.mpName); try { ent.mpTestFn(); } catch(const AssertionException& e) { wprintf(L" TEST FAILED: %hs\n", e.gets()); ++failedTests; } } if (!exts) break; exts &= ~(1 << VDFindHighestSetBitFast(exts)); } return failedTests; }
void VDUIJobControlDialog::GetJobListDispInfoW(NMLVDISPINFOW *nldi) { VDJob *vdj = g_VDJobQueue.ListGet(nldi->item.iItem); SYSTEMTIME st; SYSTEMTIME ct; static const wchar_t *const dow[]={L"Sun",L"Mon",L"Tue",L"Wed",L"Thu",L"Fri",L"Sat"}; if (!(nldi->item.mask & LVIF_TEXT)) return; nldi->item.mask = LVIF_TEXT; nldi->item.pszText[0] = 0; if (!vdj) return; uint64 *ft = &vdj->mDateEnd; switch(nldi->item.iSubItem) { case 0: VDTextAToW(nldi->item.pszText, nldi->item.cchTextMax, vdj->GetName()); break; case 1: // file in VDTextAToW(nldi->item.pszText, nldi->item.cchTextMax, VDFileSplitPath(vdj->GetInputFile())); break; case 2: // file out VDTextAToW(nldi->item.pszText, nldi->item.cchTextMax, VDFileSplitPath(vdj->GetOutputFile())); break; case 3: // time in ft = &vdj->mDateStart; case 4: // time out { FILETIME ft2, ftl; ft2.dwLowDateTime = (uint32)*ft; ft2.dwHighDateTime = (uint32)(*ft >> 32); FileTimeToLocalFileTime(&ft2, &ftl); FileTimeToSystemTime(&ftl, &st); } GetLocalTime(&ct); if (!*ft) nldi->item.pszText = L"-"; else if (ct.wYear != st.wYear || ct.wMonth != st.wMonth || ct.wDay != st.wDay) { swprintf(nldi->item.pszText, nldi->item.cchTextMax, L"%s %d %d:%02d%c" ,dow[st.wDayOfWeek] ,st.wDay ,st.wHour==12||!st.wHour ? 12 : st.wHour%12 ,st.wMinute ,st.wHour>=12 ? 'p' : 'a'); } else { swprintf(nldi->item.pszText, nldi->item.cchTextMax, L"%d:%02d%c" ,st.wHour==12||!st.wHour ? 12 : st.wHour%12 ,st.wMinute ,st.wHour>=12 ? 'p' : 'a'); } break; case 5: // status switch(vdj->GetState()) { case VDJob::kStateWaiting: nldi->item.pszText = L"Waiting" ; break; case VDJob::kStateInProgress: if (vdj->mRunnerName.empty() || vdj->IsLocal()) nldi->item.pszText = L"In progress"; else swprintf(nldi->item.pszText, nldi->item.cchTextMax, L"In progress (%hs:%d)", vdj->mRunnerName.c_str(), (uint32)vdj->GetRunnerId()); break; case VDJob::kStateStarting: if (vdj->mRunnerName.empty() || vdj->IsLocal()) nldi->item.pszText = L"Starting"; else swprintf(nldi->item.pszText, nldi->item.cchTextMax, L"Starting (%hs:%d)", vdj->mRunnerName.c_str(), (uint32)vdj->GetRunnerId()); break; case VDJob::kStateAborting: if (vdj->mRunnerName.empty() || vdj->IsLocal()) nldi->item.pszText = L"Aborting"; else swprintf(nldi->item.pszText, nldi->item.cchTextMax, L"Aborting (%hs:%d)", vdj->mRunnerName.c_str(), (uint32)vdj->GetRunnerId()); break; case VDJob::kStateCompleted: if (vdj->mRunnerName.empty() || vdj->IsLocal()) swprintf(nldi->item.pszText, nldi->item.cchTextMax, L"Done%hs", vdj->mLogEntries.empty() ? "" : " (warnings)"); else swprintf(nldi->item.pszText, nldi->item.cchTextMax, L"Done%hs (%hs:%d)", vdj->mLogEntries.empty() ? "" : " (warnings)", vdj->mRunnerName.c_str(), (uint32)vdj->GetRunnerId()); break; case VDJob::kStatePostponed: nldi->item.pszText = L"Postponed"; break; case VDJob::kStateAborted: if (vdj->mRunnerName.empty() || vdj->IsLocal()) nldi->item.pszText = L"Aborted"; else swprintf(nldi->item.pszText, nldi->item.cchTextMax, L"Aborted (%hs:%d)", vdj->mRunnerName.c_str(), (uint32)vdj->GetRunnerId()); break; case VDJob::kStateError: if (vdj->mRunnerName.empty() || vdj->IsLocal()) nldi->item.pszText = L"Error"; else swprintf(nldi->item.pszText, nldi->item.cchTextMax, L"Error (%hs:%d)", vdj->mRunnerName.c_str(), (uint32)vdj->GetRunnerId()); break; } break; } }
LRESULT VDDialogBaseW32::ActivateDialogDual(VDGUIHandle hParent) { if (VDIsWindowsNT()) return DialogBoxParamW(g_hInst, IS_INTRESOURCE(mpszDialogName) ? (LPCWSTR)mpszDialogName : VDTextAToW(mpszDialogName).c_str(), (HWND)hParent, StaticDlgProc, (LPARAM)this); else return DialogBoxParamA(g_hInst, mpszDialogName, (HWND)hParent, StaticDlgProc, (LPARAM)this); }
void JobAddBatchDirectory(const wchar_t *lpszSrc, const wchar_t *lpszDst) { // Scan source directory HANDLE h; WIN32_FIND_DATA wfd; wchar_t *s, *t; wchar_t szSourceDir[MAX_PATH], szDestDir[MAX_PATH]; wcsncpyz(szSourceDir, lpszSrc, MAX_PATH); wcsncpyz(szDestDir, lpszDst, MAX_PATH); s = szSourceDir; t = szDestDir; if (*s) { // If the path string is just \ or starts with x: or ends in a slash // then don't append a slash while(*s) ++s; if ((s==szSourceDir || s[-1]!=L'\\') && (!isalpha(szSourceDir[0]) || szSourceDir[1]!=L':' || szSourceDir[2])) *s++ = L'\\'; } if (*t) { // If the path string is just \ or starts with x: or ends in a slash // then don't append a slash while(*t) ++t; if ((t==szDestDir || t[-1]!=L'\\') && (!isalpha(szDestDir[0]) || szDestDir[1]!=L':' || szDestDir[2])) *t++ = L'\\'; } wcscpy(s, L"*.*"); h = FindFirstFile(VDTextWToA(szSourceDir).c_str(),&wfd); if (INVALID_HANDLE_VALUE != h) { do { if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { wchar_t *t2, *dot = NULL; VDTextAToW(s, (szSourceDir+MAX_PATH) - s, wfd.cFileName, -1); VDTextAToW(t, (szDestDir+MAX_PATH) - t, wfd.cFileName, -1); // Replace extension with .avi t2 = t; while(*t2) if (*t2++ == '.') dot = t2; if (dot) wcscpy(dot, L"avi"); else wcscpy(t2, L".avi"); // Add job! JobAddConfiguration(&g_dubOpts, szSourceDir, 0, szDestDir, false, NULL, 0, 0, false); } } while(FindNextFile(h,&wfd)); FindClose(h); } }
void JobCreateScript(JobScriptOutput& output, const DubOptions *opt, bool bIncludeEditList = true, bool bIncludeTextInfo = true) { char *mem= NULL; char buf[4096]; long l; int audioSourceMode = g_project->GetAudioSourceMode(); switch(audioSourceMode) { case kVDAudioSourceMode_External: { const VDStringA& encodedFileName = VDEncodeScriptString(VDStringW(g_szInputWAVFile)); const VDStringA& encodedDriverName = VDEncodeScriptString(VDTextWToU8(g_project->GetAudioSourceDriverName(), -1)); // check if we have options to write out const InputFileOptions *opts = g_project->GetAudioSourceOptions(); if (opts) { int l; char buf[256]; l = opts->write(buf, (sizeof buf)/7*3); if (l) { membase64(buf+l, (char *)buf, l); output.addf("VirtualDub.audio.SetSource(\"%s\", \"%s\", \"%s\");", encodedFileName.c_str(), encodedDriverName.c_str(), buf+l); break; } } // no options output.addf("VirtualDub.audio.SetSource(\"%s\", \"%s\");", encodedFileName.c_str(), encodedDriverName.c_str()); } break; default: if (audioSourceMode >= kVDAudioSourceMode_Source) { int index = audioSourceMode - kVDAudioSourceMode_Source; if (!index) output.addf("VirtualDub.audio.SetSource(1);"); else output.addf("VirtualDub.audio.SetSource(1,%d);", index); break; } // fall through case kVDAudioSourceMode_None: output.addf("VirtualDub.audio.SetSource(0);"); break; } output.addf("VirtualDub.audio.SetMode(%d);", opt->audio.mode); output.addf("VirtualDub.audio.SetInterleave(%d,%d,%d,%d,%d);", opt->audio.enabled, opt->audio.preload, opt->audio.interval, opt->audio.is_ms, opt->audio.offset); output.addf("VirtualDub.audio.SetClipMode(%d,%d);", opt->audio.fStartAudio, opt->audio.fEndAudio); output.addf("VirtualDub.audio.SetConversion(%d,%d,%d,0,%d);", opt->audio.new_rate, opt->audio.newPrecision, opt->audio.newChannels, opt->audio.fHighQuality); if (opt->audio.mVolume >= 0.0f) output.addf("VirtualDub.audio.SetVolume(%d);", VDRoundToInt(256.0f * opt->audio.mVolume)); else output.addf("VirtualDub.audio.SetVolume();"); if (g_ACompressionFormat) { if (g_ACompressionFormat->mExtraSize) { mem = (char *)allocmem(((g_ACompressionFormat->mExtraSize+2)/3)*4 + 1); if (!mem) throw MyMemoryError(); membase64(mem, (char *)(g_ACompressionFormat+1), g_ACompressionFormat->mExtraSize); output.addf("VirtualDub.audio.SetCompressionWithHint(%d,%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");" ,g_ACompressionFormat->mTag ,g_ACompressionFormat->mSamplingRate ,g_ACompressionFormat->mChannels ,g_ACompressionFormat->mSampleBits ,g_ACompressionFormat->mDataRate ,g_ACompressionFormat->mBlockSize ,g_ACompressionFormat->mExtraSize ,mem ,VDEncodeScriptString(g_ACompressionFormatHint).c_str() ); freemem(mem); } else output.addf("VirtualDub.audio.SetCompressionWithHint(%d,%d,%d,%d,%d,%d,\"%s\");" ,g_ACompressionFormat->mTag ,g_ACompressionFormat->mSamplingRate ,g_ACompressionFormat->mChannels ,g_ACompressionFormat->mSampleBits ,g_ACompressionFormat->mDataRate ,g_ACompressionFormat->mBlockSize ,VDEncodeScriptString(g_ACompressionFormatHint).c_str() ); } else output.addf("VirtualDub.audio.SetCompression();"); output.addf("VirtualDub.audio.EnableFilterGraph(%d);", opt->audio.bUseAudioFilterGraph); output.addf("VirtualDub.video.SetInputFormat(%d);", opt->video.mInputFormat); output.addf("VirtualDub.video.SetOutputFormat(%d);", opt->video.mOutputFormat); output.addf("VirtualDub.video.SetMode(%d);", opt->video.mode); output.addf("VirtualDub.video.SetSmartRendering(%d);", opt->video.mbUseSmartRendering); output.addf("VirtualDub.video.SetPreserveEmptyFrames(%d);", opt->video.mbPreserveEmptyFrames); output.addf("VirtualDub.video.SetFrameRate2(%u,%u,%d);", opt->video.mFrameRateAdjustHi, opt->video.mFrameRateAdjustLo, opt->video.frameRateDecimation); if (opt->video.frameRateTargetLo) { output.addf("VirtualDub.video.SetTargetFrameRate(%u,%u);", opt->video.frameRateTargetHi, opt->video.frameRateTargetLo); } output.addf("VirtualDub.video.SetIVTC(0, 0, 0, 0);"); if ((g_Vcompression.dwFlags & ICMF_COMPVARS_VALID) && g_Vcompression.fccHandler) { output.addf("VirtualDub.video.SetCompression(0x%08lx,%d,%d,%d);", g_Vcompression.fccHandler, g_Vcompression.lKey, g_Vcompression.lQ, g_Vcompression.lDataRate); l = ICGetStateSize(g_Vcompression.hic); if (l>0) { mem = (char *)allocmem(l + ((l+2)/3)*4 + 1); if (!mem) throw MyMemoryError(); if (ICGetState(g_Vcompression.hic, mem, l)<0) { freemem(mem); // throw MyError("Bad state data returned from compressor"); // Fine then, be that way. Stupid Pinnacle DV200 driver. mem = NULL; } if (mem) { membase64(mem+l, mem, l); // urk... Windows Media 9 VCM uses a very large configuration struct (~7K pre-BASE64). sprintf(buf, "VirtualDub.video.SetCompData(%d,\"", l); VDStringA line(buf); line += (mem+l); line += "\");"; output.adds(line.c_str()); freemem(mem); } } } else output.addf("VirtualDub.video.SetCompression();"); output.addf("VirtualDub.video.filters.Clear();"); // Add video filters FilterInstance *fa = (FilterInstance *)g_listFA.tail.next, *fa_next; int iFilter = 0; while(fa_next = (FilterInstance *)fa->next) { output.addf("VirtualDub.video.filters.Add(\"%s\");", strCify(fa->GetName())); if (fa->IsCroppingEnabled()) { const vdrect32& cropInsets = fa->GetCropInsets(); output.addf("VirtualDub.video.filters.instance[%d].SetClipping(%d,%d,%d,%d%s);" , iFilter , cropInsets.left , cropInsets.top , cropInsets.right , cropInsets.bottom , fa->IsPreciseCroppingEnabled() ? "" : ",0" ); } VDStringA scriptStr; if (fa->GetScriptString(scriptStr)) output.addf("VirtualDub.video.filters.instance[%d].%s;", iFilter, scriptStr.c_str()); if (!fa->IsEnabled()) output.addf("VirtualDub.video.filters.instance[%d].SetEnabled(false);", iFilter); VDParameterCurve *pc = fa->GetAlphaParameterCurve(); if (pc) { output.addf("declare curve = VirtualDub.video.filters.instance[%d].AddOpacityCurve();", iFilter); const VDParameterCurve::PointList& pts = pc->Points(); for(VDParameterCurve::PointList::const_iterator it(pts.begin()), itEnd(pts.end()); it!=itEnd; ++it) { const VDParameterCurvePoint& pt = *it; output.addf("curve.AddPoint(%g, %g, %d);", pt.mX, pt.mY, pt.mbLinear); } } ++iFilter; fa = fa_next; } // Add audio filters { VDAudioFilterGraph::FilterList::const_iterator it(g_audioFilterGraph.mFilters.begin()), itEnd(g_audioFilterGraph.mFilters.end()); int connidx = 0; int srcfilt = 0; output.addf("VirtualDub.audio.filters.Clear();"); for(; it!=itEnd; ++it, ++srcfilt) { const VDAudioFilterGraph::FilterEntry& fe = *it; output.addf("VirtualDub.audio.filters.Add(\"%s\");", strCify(VDTextWToU8(fe.mFilterName).c_str())); for(unsigned i=0; i<fe.mInputPins; ++i) { const VDAudioFilterGraph::FilterConnection& conn = g_audioFilterGraph.mConnections[connidx++]; output.addf("VirtualDub.audio.filters.Connect(%d, %d, %d, %d);", conn.filt, conn.pin, srcfilt, i); } VDPluginConfig::const_iterator itc(fe.mConfig.begin()), itcEnd(fe.mConfig.end()); for(; itc!=itcEnd; ++itc) { const unsigned idx = (*itc).first; const VDPluginConfigVariant& var = (*itc).second; switch(var.GetType()) { case VDPluginConfigVariant::kTypeU32: output.addf("VirtualDub.audio.filters.instance[%d].SetInt(%d, %d);", srcfilt, idx, var.GetU32()); break; case VDPluginConfigVariant::kTypeS32: output.addf("VirtualDub.audio.filters.instance[%d].SetInt(%d, %d);", srcfilt, idx, var.GetS32()); break; case VDPluginConfigVariant::kTypeU64: output.addf("VirtualDub.audio.filters.instance[%d].SetLong(%d, %I64d);", srcfilt, idx, var.GetU64()); break; case VDPluginConfigVariant::kTypeS64: output.addf("VirtualDub.audio.filters.instance[%d].SetLong(%d, %I64d);", srcfilt, idx, var.GetS64()); break; case VDPluginConfigVariant::kTypeDouble: output.addf("VirtualDub.audio.filters.instance[%d].SetDouble(%d, %g);", srcfilt, idx, var.GetDouble()); break; case VDPluginConfigVariant::kTypeAStr: output.addf("VirtualDub.audio.filters.instance[%d].SetString(%d, \"%s\");", srcfilt, idx, strCify(VDTextWToU8(VDTextAToW(var.GetAStr())).c_str())); break; case VDPluginConfigVariant::kTypeWStr: output.addf("VirtualDub.audio.filters.instance[%d].SetString(%d, \"%s\");", srcfilt, idx, strCify(VDTextWToU8(var.GetWStr(), -1).c_str())); break; case VDPluginConfigVariant::kTypeBlock: output.addf("VirtualDub.audio.filters.instance[%d].SetBlock(%d, %d, \"%s\");", srcfilt, idx, var.GetBlockLen(), VDEncodeBase64A(var.GetBlockPtr(), var.GetBlockLen()).c_str()); break; } } } } // Add subset information if (bIncludeEditList) { const FrameSubset& fs = g_project->GetTimeline().GetSubset(); output.addf("VirtualDub.subset.Clear();"); for(FrameSubset::const_iterator it(fs.begin()), itEnd(fs.end()); it!=itEnd; ++it) output.addf("VirtualDub.subset.Add%sRange(%I64d,%I64d);", it->bMask ? "Masked" : "", it->start, it->len); // Note that this must be AFTER the subset (we used to place it before, which was a bug). if (g_project->IsSelectionPresent()) { output.addf("VirtualDub.video.SetRangeFrames(%I64d,%I64d);", g_project->GetSelectionStartFrame(), g_project->GetSelectionEndFrame()); } else { output.addf("VirtualDub.video.SetRange();"); } } // Add text information if (bIncludeTextInfo) { typedef std::list<std::pair<uint32, VDStringA> > tTextInfo; const tTextInfo& textInfo = g_project->GetTextInfo(); output.addf("VirtualDub.project.ClearTextInfo();"); for(tTextInfo::const_iterator it(textInfo.begin()), itEnd(textInfo.end()); it!=itEnd; ++it) { char buf[5]={0}; memcpy(buf, &(*it).first, 4); output.addf("VirtualDub.project.AddTextInfo(\"%s\", \"%s\");", buf, VDEncodeScriptString((*it).second).c_str()); } } }