Skip to content

Commit

Permalink
Merged PR 2844732: IAppx*Utf8 interfaces variants
Browse files Browse the repository at this point in the history
Add UTF8 variant to public APIs that use LPWSTR or LPCWSTR.

New Interfaces:
•	IAppxBlockMapFileUtf8
•	IAppxBlockMapReaderUtf8
•	IAppxBundleManifestPackageInfoUtf8
•	IAppxBundleReaderUtf8
•	IAppxFactoryUtf8
•	IAppxFileUtf8
•	IAppxManifestApplicationUtf8
•	IAppxManifestPackageDependencyUtf8
•	IAppxManifestPackageIdUtf8
•	IAppxManifestPropertiesUtf8
•	IAppxManifestQualifiedResourceUtf8
•	IAppxManifestResourcesEnumeratorUtf8
•	IAppxManifestTargetDeviceFamilyUtf8
•	IAppxPackageReaderUtf8

This change also fixes a bug were all non-AppPackaging public interfaces (eg. IMsixElement) had their IID_I* set to 0 for Windows only. GUID definition is now defined on AppxPackaging.hpp removing the need of AppPackaging_i.cpp
  • Loading branch information
msftrubengu authored and Rubén Guerrero Samaniego committed Feb 9, 2019
1 parent cc3fcf0 commit 7c84b3f
Show file tree
Hide file tree
Showing 32 changed files with 1,164 additions and 787 deletions.
4 changes: 2 additions & 2 deletions sample/OverrideLanguageSample/OverrideLanguageSample.cpp
Expand Up @@ -114,12 +114,12 @@ class OverrideLanguages final : public IMsixApplicabilityLanguagesEnumerator
OverrideLanguages(char** languages, int numLanguages) : m_languages(languages), m_numLanguages(numLanguages) {}

// IUnknown
virtual ULONG STDMETHODCALLTYPE AddRef() override
virtual ULONG STDMETHODCALLTYPE AddRef() noexcept override
{
return ++m_ref;
}

virtual ULONG STDMETHODCALLTYPE Release() override
virtual ULONG STDMETHODCALLTYPE Release() noexcept override
{
if (--m_ref == 0)
{
Expand Down
20 changes: 13 additions & 7 deletions sample/OverrideStreamSample/OverrideStreamSample.cpp
Expand Up @@ -187,12 +187,12 @@ class MyStream final : public IStream

// IUnknown.
// This is the loong way. Look at ComClass<> in src\inc\ComHelper.hpp for an example on how to avoid implementing IUnknown without pain.
virtual ULONG STDMETHODCALLTYPE AddRef() override
virtual ULONG STDMETHODCALLTYPE AddRef() noexcept override
{
return ++m_ref;
}

virtual ULONG STDMETHODCALLTYPE Release() override
virtual ULONG STDMETHODCALLTYPE Release() noexcept override
{
if (--m_ref == 0)
{
Expand Down Expand Up @@ -342,12 +342,12 @@ class MyStreamFactory final : public IMsixStreamFactory
MyStreamFactory(const std::wstring& path) : m_path(path), m_ref(1) {}

// IUnknown
virtual ULONG STDMETHODCALLTYPE AddRef() override
virtual ULONG STDMETHODCALLTYPE AddRef() noexcept override
{
return ++m_ref;
}

virtual ULONG STDMETHODCALLTYPE Release() override
virtual ULONG STDMETHODCALLTYPE Release() noexcept override
{
if (--m_ref == 0)
{
Expand Down Expand Up @@ -382,16 +382,22 @@ class MyStreamFactory final : public IMsixStreamFactory

// IMsixStreamFactory
virtual HRESULT STDMETHODCALLTYPE CreateStreamOnRelativePath(LPCWSTR relativePath, IStream** stream) noexcept override
{
return CreateStreamOnRelativePathUtf8(utf16_to_utf8(relativePath).c_str(), stream);
}

virtual HRESULT STDMETHODCALLTYPE CreateStreamOnRelativePathUtf8(LPCSTR relativePath, IStream** stream) noexcept override
{
*stream = nullptr;
ComPtr<IStream> result;
auto path = utf16_to_utf8(m_path);
#ifdef WIN32
std::wstring fullFileName = m_path + std::wstring(L"\\") + relativePath;
std::string fullFileName = path + std::string("\\") + relativePath;
#else
std::wstring fullFileName = m_path + std::wstring(L"/") + relativePath;
std::string fullFileName = path + std::string("/") + relativePath;
std::replace(fullFileName.begin(), fullFileName.end(), '\\', '/' );
#endif
RETURN_IF_FAILED(ComPtr<IStream>::MakeAndInitialize<MyStream>(&result, utf16_to_utf8(fullFileName), MyStream::Mode::READ));
RETURN_IF_FAILED(ComPtr<IStream>::MakeAndInitialize<MyStream>(&result, fullFileName, MyStream::Mode::READ));
if (result.Get() != nullptr)
{
*stream = result.Detach();
Expand Down
23 changes: 16 additions & 7 deletions src/inc/AppxBlockMapObject.hpp
Expand Up @@ -20,9 +20,8 @@
#include "Enumerators.hpp"

// internal interface
EXTERN_C const IID IID_IAppxBlockMapInternal;
#ifndef WIN32
// {67fed21a-70ef-4175-8f12-415b213ab6d2}
#ifndef WIN32
interface IAppxBlockMapInternal : public IUnknown
#else
#include "Unknwn.h"
Expand All @@ -31,11 +30,11 @@ class IAppxBlockMapInternal : public IUnknown
#endif
{
public:
virtual std::vector<std::string> GetFileNames() = 0;
virtual std::vector<MSIX::Block> GetBlocks(const std::string& fileName) = 0;
virtual std::vector<std::string> GetFileNames() = 0;
virtual std::vector<MSIX::Block> GetBlocks(const std::string& fileName) = 0;
virtual MSIX::ComPtr<IAppxBlockMapFile> GetFile(const std::string& fileName) = 0;
};
SpecializeUuidOfImpl(IAppxBlockMapInternal);
MSIX_INTERFACE(IAppxBlockMapInternal, 0x67fed21a,0x70ef,0x4175,0x8f,0x12,0x41,0x5b,0x21,0x3a,0xb6,0xd2);

namespace MSIX {

Expand Down Expand Up @@ -66,7 +65,7 @@ namespace MSIX {
Block* m_block;
};

class AppxBlockMapFile final : public MSIX::ComClass<AppxBlockMapFile, IAppxBlockMapFile>
class AppxBlockMapFile final : public MSIX::ComClass<AppxBlockMapFile, IAppxBlockMapFile, IAppxBlockMapFileUtf8 >
{
public:
AppxBlockMapFile(
Expand Down Expand Up @@ -129,6 +128,13 @@ namespace MSIX {
return static_cast<HRESULT>(Error::NotImplemented);
}

// IAppxBlockMapFileUtf8
HRESULT STDMETHODCALLTYPE GetName(LPSTR *name) noexcept override try
{
ThrowHrIfFailed(m_factory->MarshalOutStringUtf8(m_name, name));
return static_cast<HRESULT>(Error::OK);
} CATCH_RETURN();

private:
std::vector<ComPtr<IAppxBlockMapBlock>> m_blockMapBlocks;
std::vector<Block>* m_blocks;
Expand All @@ -139,7 +145,7 @@ namespace MSIX {
};

// Object backed by AppxBlockMap.xml
class AppxBlockMapObject final : public MSIX::ComClass<AppxBlockMapObject, IAppxBlockMapReader, IVerifierObject, IAppxBlockMapInternal>
class AppxBlockMapObject final : public MSIX::ComClass<AppxBlockMapObject, IAppxBlockMapReader, IVerifierObject, IAppxBlockMapInternal, IAppxBlockMapReaderUtf8 >
{
public:
AppxBlockMapObject(IMsixFactory* factory, const ComPtr<IStream>& stream);
Expand All @@ -161,6 +167,9 @@ namespace MSIX {
std::vector<Block> GetBlocks(const std::string& fileName) override;
MSIX::ComPtr<IAppxBlockMapFile> GetFile(const std::string& fileName) override;

// IAppxBlockMapReaderUtf8
HRESULT STDMETHODCALLTYPE GetFile(LPCSTR filename, IAppxBlockMapFile **file) noexcept override;

protected:
std::map<std::string, std::vector<Block>> m_blockMap;
std::map<std::string, ComPtr<IAppxBlockMapFile>> m_blockMapFiles;
Expand Down
24 changes: 15 additions & 9 deletions src/inc/AppxBundleManifest.hpp
Expand Up @@ -12,9 +12,8 @@
#include "Applicability.hpp"
#include "VerifierObject.hpp"

EXTERN_C const IID IID_IBundleInfo;
#ifndef WIN32
// {ff82ffcd-747a-4df9-8879-853ab9dd15a1}
#ifndef WIN32
interface IBundleInfo : public IUnknown
#else
#include "Unknwn.h"
Expand All @@ -25,10 +24,10 @@ class IBundleInfo : public IUnknown
public:
virtual std::vector<MSIX::ComPtr<IAppxBundleManifestPackageInfo>>& GetPackages() = 0;
};
MSIX_INTERFACE(IBundleInfo, 0xff82ffcd,0x747a,0x4df9,0x88,0x79,0x85,0x3a,0xb9,0xdd,0x15,0xa1);

EXTERN_C const IID IID_IAppxBundleManifestPackageInfoInternal;
#ifndef WIN32
// {32e6fcf0-729b-401d-9dbc-f927b494f9af}
#ifndef WIN32
interface IAppxBundleManifestPackageInfoInternal : public IUnknown
#else
#include "Unknwn.h"
Expand All @@ -42,9 +41,7 @@ class IAppxBundleManifestPackageInfoInternal : public IUnknown
virtual const std::uint64_t GetOffset() = 0;
virtual bool HasQualifiedResources() = 0;
};

SpecializeUuidOfImpl(IAppxBundleManifestPackageInfoInternal);
SpecializeUuidOfImpl(IBundleInfo);
MSIX_INTERFACE(IAppxBundleManifestPackageInfoInternal, 0x32e6fcf0,0x729b,0x401d,0x9d,0xbc,0xf9,0x27,0xb4,0x94,0xf9,0xaf);

namespace MSIX {
class AppxBundleManifestObject final : public ComClass<AppxBundleManifestObject, IAppxBundleManifestReader, IVerifierObject, IBundleInfo>
Expand Down Expand Up @@ -73,7 +70,7 @@ namespace MSIX {
std::vector<ComPtr<IAppxBundleManifestPackageInfo>> m_packages;
};

class AppxBundleQualifiedResource final : public MSIX::ComClass<AppxBundleQualifiedResource, IAppxManifestQualifiedResource>
class AppxBundleQualifiedResource final : public MSIX::ComClass<AppxBundleQualifiedResource, IAppxManifestQualifiedResource, IAppxManifestQualifiedResourceUtf8>
{
public:
AppxBundleQualifiedResource(IMsixFactory* factory, const std::string& language) : m_factory(factory), m_language(language) {}
Expand All @@ -95,12 +92,18 @@ namespace MSIX {
return static_cast<HRESULT>(Error::NotImplemented);
}

// IAppxManifestQualifiedResourceUtf8
HRESULT STDMETHODCALLTYPE GetLanguage(LPSTR *language) noexcept override try
{
return m_factory->MarshalOutStringUtf8(m_language, language);
} CATCH_RETURN();

protected:
IMsixFactory* m_factory;
std::string m_language;
};

class AppxBundleManifestPackageInfo final : public ComClass<AppxBundleManifestPackageInfo, IAppxBundleManifestPackageInfo, IAppxBundleManifestPackageInfoInternal>
class AppxBundleManifestPackageInfo final : public ComClass<AppxBundleManifestPackageInfo, IAppxBundleManifestPackageInfo, IAppxBundleManifestPackageInfoInternal, IAppxBundleManifestPackageInfoUtf8>
{
public:
AppxBundleManifestPackageInfo(
Expand Down Expand Up @@ -130,6 +133,9 @@ namespace MSIX {
const std::uint64_t GetOffset() override { return m_offset; }
bool HasQualifiedResources() override { return !m_languages.empty(); }

// IAppxBundleManifestPackageInfoUtf8
HRESULT STDMETHODCALLTYPE GetFileName(LPSTR *fileName) noexcept override;

private:
IMsixFactory* m_factory;
std::string m_fileName;
Expand Down
25 changes: 14 additions & 11 deletions src/inc/AppxFactory.hpp
Expand Up @@ -15,7 +15,7 @@
#include <vector>

namespace MSIX {
class AppxFactory final : public ComClass<AppxFactory, IMsixFactory, IAppxFactory, IXmlFactory, IAppxBundleFactory, IMsixFactoryOverrides>
class AppxFactory final : public ComClass<AppxFactory, IMsixFactory, IAppxFactory, IXmlFactory, IAppxBundleFactory, IMsixFactoryOverrides, IAppxFactoryUtf8>
{
public:
AppxFactory(MSIX_VALIDATION_OPTION validationOptions, MSIX_APPLICABILITY_OPTIONS applicability, COTASKMEMALLOC* memalloc, COTASKMEMFREE* memfree ) :
Expand All @@ -30,16 +30,11 @@ namespace MSIX {
~AppxFactory() {}

// IAppxFactory
HRESULT STDMETHODCALLTYPE CreatePackageWriter(IStream* outputStream, APPX_PACKAGE_SETTINGS* , IAppxPackageWriter** packageWriter) noexcept override;

HRESULT STDMETHODCALLTYPE CreatePackageWriter(IStream* outputStream, APPX_PACKAGE_SETTINGS* , IAppxPackageWriter** packageWriter) noexcept override;
HRESULT STDMETHODCALLTYPE CreatePackageReader (IStream* inputStream, IAppxPackageReader** packageReader) noexcept override;
HRESULT STDMETHODCALLTYPE CreateManifestReader(IStream* inputStream, IAppxManifestReader** manifestReader) noexcept override ;
HRESULT STDMETHODCALLTYPE CreateBlockMapReader (IStream* inputStream, IAppxBlockMapReader** blockMapReader) noexcept override;

HRESULT STDMETHODCALLTYPE CreateValidatedBlockMapReader (
IStream* blockMapStream,
LPCWSTR signatureFileName,
IAppxBlockMapReader** blockMapReader) noexcept override;
HRESULT STDMETHODCALLTYPE CreateManifestReader(IStream* inputStream, IAppxManifestReader** manifestReader) noexcept override;
HRESULT STDMETHODCALLTYPE CreateBlockMapReader(IStream* inputStream, IAppxBlockMapReader** blockMapReader) noexcept override;
HRESULT STDMETHODCALLTYPE CreateValidatedBlockMapReader(IStream* blockMapStream, LPCWSTR signatureFileName, IAppxBlockMapReader** blockMapReader) noexcept override;

// IAppxBundleFactory
HRESULT STDMETHODCALLTYPE CreateBundleWriter(IStream *outputStream, UINT64 bundleVersion, IAppxBundleWriter **bundleWriter) noexcept override;
Expand All @@ -48,10 +43,11 @@ namespace MSIX {

// IMsixFactory
HRESULT MarshalOutString(std::string& internal, LPWSTR *result) noexcept override;
HRESULT MarshalOutWstring(std::wstring& internal, LPWSTR* result) noexcept override;
HRESULT MarshalOutStringUtf8(std::string& internal, LPSTR* result) noexcept override;
HRESULT MarshalOutBytes(std::vector<std::uint8_t>& data, UINT32* size, BYTE** buffer) noexcept override;
MSIX_VALIDATION_OPTION GetValidationOptions() override { return m_validationOptions; }
ComPtr<IStream> GetResource(const std::string& resource) override;
HRESULT MarshalOutWstring(std::wstring& internal, LPWSTR* result) noexcept override;

// IXmlFactory
MSIX::ComPtr<IXmlDom> CreateDomFromStream(XmlContentType footPrintType, const ComPtr<IStream>& stream) override
Expand All @@ -63,6 +59,9 @@ namespace MSIX {
HRESULT STDMETHODCALLTYPE SpecifyExtension(MSIX_FACTORY_EXTENSION name, IUnknown* extension) noexcept override;
HRESULT STDMETHODCALLTYPE GetCurrentSpecifiedExtension(MSIX_FACTORY_EXTENSION name, IUnknown** extension) noexcept override;

// IAppxFactoryUtf8
HRESULT STDMETHODCALLTYPE CreateValidatedBlockMapReader(IStream* blockMapStream, LPCSTR signatureFileName, IAppxBlockMapReader** blockMapReader) noexcept override;

ComPtr<IXmlFactory> m_xmlFactory;
COTASKMEMALLOC* m_memalloc;
COTASKMEMFREE* m_memfree;
Expand All @@ -72,5 +71,9 @@ namespace MSIX {
MSIX_APPLICABILITY_OPTIONS m_applicabilityFlags;
ComPtr<IMsixStreamFactory> m_streamFactory;
ComPtr<IMsixApplicabilityLanguagesEnumerator> m_applicabilityLanguagesEnumerator;

private:
template<typename T>
void MarshalOutStringHelper(std::size_t size, T* from, T** to);
};
}
13 changes: 12 additions & 1 deletion src/inc/AppxFile.hpp
Expand Up @@ -20,7 +20,7 @@
#include "StreamBase.hpp"

namespace MSIX {
class AppxFile : public ComClass<AppxFile, IAppxFile>
class AppxFile : public ComClass<AppxFile, IAppxFile, IAppxFileUtf8>
{
public:
AppxFile(IMsixFactory* factory, const std::string& name, const ComPtr<IStream>& stream) : m_factory(factory), m_name(name), m_stream(stream)
Expand Down Expand Up @@ -74,6 +74,17 @@ namespace MSIX {
return static_cast<HRESULT>(Error::OK);
} CATCH_RETURN();

// IAppxFileUtf8
virtual HRESULT STDMETHODCALLTYPE GetContentType(LPSTR* contentType) noexcept override
{
return static_cast<HRESULT>(Error::NotImplemented);
}

virtual HRESULT STDMETHODCALLTYPE GetName(LPSTR* fileName) noexcept override try
{
return m_factory->MarshalOutStringUtf8(m_name, fileName);
} CATCH_RETURN();

protected:
std::string m_name;
ComPtr<IStream> m_stream;
Expand Down

0 comments on commit 7c84b3f

Please sign in to comment.