-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathConverter.cpp
119 lines (97 loc) · 3.11 KB
/
Converter.cpp
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
#include "pch.h"
#include "Converter.h"
#include "Definitions.h"
#include "stringhelper.h"
#include "EmulatorFileHandler.h"
#include "DirectXPage.xaml.h"
using namespace Windows::UI::Xaml::Media::Imaging;
using namespace VBA10;
using namespace Concurrency;
using namespace Platform;
using namespace std;
using namespace Windows::Storage;
using namespace Windows::Storage::Streams;
using namespace Windows::Storage::AccessCache;
IsoImageConverter::IsoImageConverter()
{
}
IsoImageConverter::~IsoImageConverter()
{
}
Object^ IsoImageConverter::Convert(Object^ value, TypeName targetType, Object^ parameter, String^ language)
{
try
{
BitmapImage^ bitmap = ref new BitmapImage();
String^ path = (String^)value;
if (path->Equals(DEFAULT_SNAPSHOT))
return path;
if (!path->IsEmpty())
{
//using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
//{
// using (IsolatedStorageFileStream fs = isoStore.OpenFile(path, System.IO.FileMode.Open, System.IO.FileAccess.Read))
// {
// bitmap.SetSource(fs);
// }
//}
//create_task([this, bitmap, path]
//{
// if (IsROMLoaded()) //create snapshot
// return DirectXPage::Current->TakeSnapshot();
// else
// return create_task([] {});
//
//}).then([this, bitmap, path] {
LoadImageFromPath(bitmap, path);
//});
}
return bitmap;
}
catch (Exception^ ex)
{
return nullptr;
}
}
task<void> IsoImageConverter::LoadImageFromPath(BitmapImage^ bitmap, String^ filepath)
{
Platform::String ^file_path = filepath;
wstring wfilepath(file_path->Begin(), file_path->End());
wstring folderpath;
wstring filename;
wstring filenamenoext;
wstring ext;
splitFilePath(wfilepath, folderpath, filename, filenamenoext, ext);
replace(folderpath.begin(), folderpath.end(), ':', '_');
replace(folderpath.begin(), folderpath.end(), '/', '_');
replace(folderpath.begin(), folderpath.end(), '\\', '_');
Platform::String^ ptoken = ref new Platform::String(folderpath.c_str());
Platform::String^ pfilename = ref new Platform::String(filename.c_str());
return create_task(StorageApplicationPermissions::FutureAccessList->GetFolderAsync(ptoken))
.then([bitmap, pfilename](StorageFolder^ folder)
{
return folder->GetFileAsync(pfilename);
}).then([bitmap](StorageFile^ file)
{
return file->OpenAsync(FileAccessMode::Read);
}).then([bitmap](IRandomAccessStream^ stream)
{
return bitmap->SetSourceAsync(stream);
});
}
Object^ IsoImageConverter::ConvertBack(Object^ value, TypeName targetType, Object^ parameter, String^ language)
{
return nullptr; //doing one-way binding so this is not required.
}
Object^ VisibilityConverter::Convert(Object^ value, TypeName targetType, Object^ parameter, String^ language)
{
bool visible = (bool)value;
if (visible)
return Windows::UI::Xaml::Visibility::Visible;
else
return Windows::UI::Xaml::Visibility::Collapsed;
}
Object^ VisibilityConverter::ConvertBack(Object^ value, TypeName targetType, Object^ parameter, String^ language)
{
return nullptr;
}