ShellLink::ShellLink(PCWSTR path, bool write) : m_path(path) { Object<IPersistFile> ppf; CheckApiError(::CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IPersistFile, (PVOID* )&ppf)); CheckCom(ppf->Load(m_path.c_str(), write ? STGM_READWRITE : STGM_READ)); CheckCom(ppf->QueryInterface(IID_IShellLink, (PVOID*)&m_lnk)); CheckCom(m_lnk->Resolve(NULL, SLR_ANY_MATCH | SLR_NO_UI)); }
ssize_t ArchiveExtract::execute() { LogTrace(); Com::Object<IArchiveExtractCallback> extractCallback(new ExtractCallback(m_archive, m_dest)); CheckCom(m_archive->Extract(nullptr, (UInt32 )-1, false, extractCallback)); return 0; }
ShellLink ShellLink::create(PCWSTR path) { ShellLink ret; ret.m_path = path; CheckCom(::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (PVOID*)&ret.m_lnk)); return ret; }
void Archive::open_archive(const Lib & lib, const ustring & path) { LogNoise(L"%p, '%s'\n", &lib, path.c_str()); Com::Object<IInStream> stream(new FileReadStream(path)); Com::Object<IArchiveOpenCallback> openCallback(new OpenCallback); for (auto it = lib.codecs().begin(); it != lib.codecs().end(); ++it) { LogNoise(L"codec: '%s'\n", it->name.c_str()); CheckCom(stream->Seek(0, STREAM_SEEK_SET, nullptr)); CheckCom(lib.CreateObject(&it->guid, &IID_IInArchive, (PVOID*)&m_arc)); if (m_arc->Open(stream, &max_check_size, openCallback) == S_OK) { m_codec = it; return; } } CheckApiError(ERROR_INVALID_DATA); }
ShellIcon ShellLink::icon() const { Base::auto_array<wchar_t> buf(Base::MAX_PATH_LEN); int ind; CheckCom(m_lnk->GetIconLocation(buf.data(), buf.size(), &ind)); return ShellIcon(ustring(buf.data()), ind); }
void ComIO::OpenAndInitCom() { /* hCom = OpenCommPort(ComIndex); if(hCom) CommPort_Init(hCom);*/ if(CheckCom(ComIndex)) { printf("Find Com%d\r\n", ComIndex); return ; } for(int i = 0; i < 20; i++) { if((i != ComIndex) && CheckCom(i)) { printf("Find Com%d\r\n", i); break; } } }
void Methods::cache(const Lib & lib) { UInt32 num_methods = 0; CheckCom(lib.GetNumberOfMethods(&num_methods)); clear(); for (size_t idx = 0; idx < num_methods; ++idx) { emplace_back(lib, idx); } }
int ShellLink::show() const { int ret; CheckCom(m_lnk->GetShowCmd(&ret)); return ret; }
ArchiveSequence::const_iterator ArchiveSequence::at(size_t index) const { if (index >= size()) CheckCom(TYPE_E_OUTOFBOUNDS); return const_iterator(*this, index); }
void ShellLink::show(int in) { CheckCom(m_lnk->SetShowCmd(in)); }
void ShellLink::descr(const ustring &in) { CheckCom(m_lnk->SetDescription(in.c_str())); }
void ShellLink::path(const ustring &in) { CheckCom(m_lnk->SetPath(in.c_str())); }
void ShellLink::args(const ustring &in) { CheckCom(m_lnk->SetArguments(in.c_str())); }
void ShellLink::write() const { Object<IPersistFile> ppf; CheckCom(m_lnk->QueryInterface(IID_IPersistFile, (PVOID* )&ppf)); CheckCom(ppf->Save(m_path.c_str(), FALSE)); }
ustring ShellLink::args() const { Base::auto_array<wchar_t> buf(Base::MAX_PATH_LEN); CheckCom(m_lnk->GetArguments(buf.data(), buf.size())); return ustring(buf); }
ustring ShellLink::path() const { Base::auto_array<wchar_t> buf(Base::MAX_PATH_LEN); CheckCom(m_lnk->GetPath(buf.data(), buf.size(), nullptr, 0)); return ustring(buf); }
ustring ShellLink::descr() const { Base::auto_array<wchar_t> buf(Base::MAX_PATH_LEN); CheckCom(m_lnk->GetDescription(buf.data(), buf.size())); return ustring(buf); }
ustring ShellLink::work_dir() const { Base::auto_array<wchar_t> buf(Base::MAX_PATH_LEN); CheckCom(m_lnk->GetWorkingDirectory(buf.data(), buf.size())); return ustring(buf.data()); }
void ShellLink::work_dir(const ustring &in) { CheckCom(m_lnk->SetWorkingDirectory(in.c_str())); }