1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
/* Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license that can
* be found in the License.html file in the root of the source tree.
*/
//---------------------------------------------------------------------------
#include <windows.h>
#include "pch.h"
#include "AppCore.h"
#include "ZenLib/FileName.h"
#include "ZenLib/Ztring.h"
#include "ZenLib/File.h"
#include "ZenLib/Dir.h"
//---------------------------------------------------------------------------
using namespace ZenLib;
using namespace MediaInfo;
using namespace MediaInfoLib;
using namespace Platform::Collections;
using namespace Windows::ApplicationModel;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::Security::Cryptography;
using namespace Windows::Security::Cryptography::Core;
using namespace Windows::Storage;
using namespace Windows::Storage::AccessCache;
using namespace Windows::Storage::Streams;
using namespace Concurrency;
//---------------------------------------------------------------------------
// Init
//---------------------------------------------------------------------------
IObservableVector<View^>^ AppCore::_Views=nullptr;
//---------------------------------------------------------------------------
// Properties
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
Platform::String^ AppCore::AppVersion::get()
{
PackageVersion Version=Package::Current->Id->Version;
Platform::String^ VersionString=Version.Major.ToString();
if (Version.Minor<10)
VersionString+=L".0"+Version.Minor.ToString();
else
VersionString+=L"."+Version.Minor.ToString();
if (Version.Build || Version.Revision)
VersionString+=L"."+Version.Build.ToString();
if (Version.Revision)
VersionString+=L"."+Version.Revision.ToString();
return VersionString;
}
//---------------------------------------------------------------------------
Platform::String^ AppCore::Version::get()
{
MediaInfoLib::MediaInfo MI;
ZenLib::Ztring Result=MI.Option(__T("Info_Version"));
Result.FindAndReplace(__T("MediaInfoLib - v"), __T(""));
return ref new Platform::String(Result.c_str());
}
//---------------------------------------------------------------------------
IObservableVector<View^>^ AppCore::ViewList::get()
{
if (_Views)
return _Views;
MediaInfoLib::MediaInfo MI;
_Views=ref new Platform::Collections::Vector<::MediaInfo::View^>();
_Views->Append(ref new ::MediaInfo::View("Easy", "Easy", "text/plain", View==L"Easy", false));
_Views->Append(ref new ::MediaInfo::View("Sheet", "Sheet", "text/plain", View==L"Sheet", false));
ZenLib::ZtringListList ViewsCSV=ZenLib::ZtringListList();
ViewsCSV.Separator_Set(0, ZenLib::EOL);
ViewsCSV.Separator_Set(1, __T(","));
ViewsCSV.Write(MI.Option(__T("Info_OutputFormats_CSV")));
for (size_t It=0; It<ViewsCSV.size(); It++)
{
ZenLib::ZtringList Current=ViewsCSV[It];
if (Current.size()>=3)
{
Platform::String^ Name=ref new Platform::String(Current[0].c_str());
Platform::String^ Desc=ref new Platform::String(Current[1].c_str());
Platform::String^ Mime=ref new Platform::String(Current[2].c_str());
_Views->Append(ref new ::MediaInfo::View(Name, Desc, Mime, View==Name, true));
}
}
return _Views;
}
//---------------------------------------------------------------------------
Platform::String^ AppCore::View::get()
{
ApplicationDataContainer^ LocalSettings=ApplicationData::Current->LocalSettings;
Platform::String^ Current=safe_cast<Platform::String^>(LocalSettings->Values->Lookup(L"View"));
if (!Current||!Current->Length())
Current=L"Easy";
return Current;
}
//---------------------------------------------------------------------------
void AppCore::View::set(Platform::String^ Value)
{
ApplicationDataContainer^ LocalSettings=ApplicationData::Current->LocalSettings;
Platform::String^ Current=safe_cast<Platform::String^>(LocalSettings->Values->Lookup(L"View"));
if (Current && Current->Length() && Current==Value)
return;
LocalSettings->Values->Insert(L"View", Value);
if (_Views)
{
for (::MediaInfo::View^ It:_Views)
if (It->Name==Value)
It->Current=true;
else if(It->Current)
It->Current=false;
}
ViewChangedEvent(Value);
}
//---------------------------------------------------------------------------
// Functions
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
Platform::String^ AppCore::Get_Mime(Platform::String^ Name)
{
if (Name==L"Easy" || Name==L"Sheet")
return L"Text/plain";
for (::View^ It : ViewList)
{
if (It->Name==Name)
return It->Mime;
}
return L"";
}
//---------------------------------------------------------------------------
Platform::String^ AppCore::Get_Stream_Name(size_t StreamKind)
{
switch (static_cast<stream_t>(StreamKind))
{
case Stream_General: return L"General";
case Stream_Video: return L"Video";
case Stream_Audio: return L"Audio";
case Stream_Text: return L"Text";
case Stream_Other: return L"Other";
case Stream_Image: return L"Image";
case Stream_Menu: return L"Menu";
default: return L"Unknown Stream";
}
}
//---------------------------------------------------------------------------
size_t AppCore::Get_Stream_Id(Platform::String^ StreamKind)
{
if (StreamKind==L"General")
return static_cast<size_t>(Stream_General);
else if (StreamKind==L"Video")
return static_cast<size_t>(Stream_Video);
else if (StreamKind==L"Audio")
return static_cast<size_t>(Stream_Audio);
else if (StreamKind==L"Text")
return static_cast<size_t>(Stream_Text);
else if (StreamKind==L"Other")
return static_cast<size_t>(Stream_Other);
else if (StreamKind==L"Image")
return static_cast<size_t>(Stream_Image);
else if (StreamKind==L"Menu")
return static_cast<size_t>(Stream_Menu);
return static_cast<size_t>(Stream_Max);
}
//---------------------------------------------------------------------------
Platform::String^ AppCore::Create_Report(Platform::String^ Path)
{
MediaInfoLib::MediaInfo MI;
MI.Option(__T("Inform"), __T("MIXML"));
MI.Option(__T("Input_Compressed"), __T(""));
MI.Option(__T("Inform_Compress"), __T("zlib+base64"));
MI.Open(Ztring(Path->Data()));
Ztring Report=MI.Inform();
MI.Close();
return ref new Platform::String(Report.c_str());
}
//---------------------------------------------------------------------------
void AppCore::Add_Item_To_FutureAccessList(IStorageItem^ Item)
{
if (!Item)
return;
IBuffer^ InBuffer=CryptographicBuffer::ConvertStringToBinary(Item->Path, BinaryStringEncoding::Utf16LE);
HashAlgorithmProvider^ Provider=HashAlgorithmProvider::OpenAlgorithm("SHA256");
IBuffer^ OutBuffer=Provider->HashData(InBuffer);
Platform::String^ Hash=CryptographicBuffer::EncodeToBase64String(OutBuffer);
StorageApplicationPermissions::FutureAccessList->AddOrReplace(Hash, Item);
}
|