This repository has been archived by the owner on Jan 29, 2018. It is now read-only.
/
PaintLauncher.cs
85 lines (74 loc) · 2.7 KB
/
PaintLauncher.cs
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Catrobat.Core;
using Catrobat.Core.Objects;
using Catrobat.Core.Storage;
using Catrobat.Core.ZIP;
using Windows.Storage;
using Catrobat.Core.Objects.Costumes;
namespace Catrobat.IDEWindowsPhone.Misc
{
public class PaintLauncher
{
private static string _imageFolderPath;
private static string _imageFileName;
private const string DummyFileExtension = ".catrobatimage";
public async static Task<bool> LaunchPaint(string pathToImage)
{
try
{
var splitPath = pathToImage.Split('/');
_imageFileName = splitPath[splitPath.Length - 1];
_imageFolderPath = "";
for(int i = 0; i < splitPath.Length - 1; i++)
{
if (_imageFolderPath != "")
_imageFolderPath += "/";
_imageFolderPath += splitPath[i];
}
using (IStorage storage = StorageSystem.GetStorage())
{
storage.DeleteDirectory(CatrobatContext.TempPaintImagePath);
storage.CopyFile(pathToImage, CatrobatContext.TempPaintImagePath + "/" + _imageFileName + DummyFileExtension);
}
var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
var tempFolder = await localFolder.CreateFolderAsync(CatrobatContext.TempPaintImagePath.Split('/')[0], CreationCollisionOption.OpenIfExists);
var tempImageFolder = await localFolder.CreateFolderAsync(CatrobatContext.TempPaintImagePath.Split('/')[1], CreationCollisionOption.ReplaceExisting);
var imageFile = await tempImageFolder.CreateFileAsync(_imageFileName + DummyFileExtension, CreationCollisionOption.ReplaceExisting);
await Windows.System.Launcher.LaunchFileAsync(imageFile);
return true;
}
catch (Exception)
{
return false;
}
}
public static bool RecieveImageFromPaint()
{
try
{
var tempFilePath = CatrobatContext.TempPaintImagePath + "/" + _imageFileName + DummyFileExtension;
var originalFilePath = _imageFolderPath + "/" + _imageFileName;
using (IStorage storage = StorageSystem.GetStorage())
{
if (storage.FileExists(tempFilePath))
{
storage.FileExists(originalFilePath);
storage.DeleteFile(originalFilePath);
storage.CopyFile(tempFilePath, originalFilePath);
storage.DeleteDirectory(CatrobatContext.TempPaintImagePath);
}
}
return true;
}
catch (Exception)
{
return false;
}
}
}
}