public override void LoadFileDialog(FolderLocations folderLocation, int maxWidth, int maxHeight, int x, int y, int width, int height, string[] fileTypes, StreamLoadedCallbackMethod streamLoadedCallback)
		{
			if (streamLoadedCallback == null) return;
			string filename = EditorUtility.OpenFilePanel("Load file", "", generateFilterValue(fileTypes));
			if (!string.IsNullOrEmpty(filename))
			{
				if (maxWidth == 0 || maxHeight == 0 || folderLocation != FolderLocations.Pictures)
				{
					streamLoadedCallback(new FileStream(filename, FileMode.Open, FileAccess.Read), true);
				}
				else
				{
					var newStream = new MemoryStream();
					try
					{
						using (var stream = new FileStream(filename, FileMode.Open, FileAccess.Read))
						{
							IImageDecoder decoder = null;
							switch (Path.GetExtension(filename).ToLower())
							{
								case ".jpg": decoder = new JpegDecoder(); break;
								case ".jpeg": decoder = new JpegDecoder(); break;
								case ".png": decoder = new PngDecoder(); break;
								default:
									Debug.LogError("Unsuported file ext type: " + Path.GetExtension(filename));
									streamLoadedCallback(null, false);
									return;
							}
							var image = new ExtendedImage();
							decoder.Decode(image, stream);
							var newSize = MathUtilities.FitInViewIfLarger(image.PixelWidth, image.PixelHeight, maxWidth, maxHeight);
							var newImage = ExtendedImage.Resize(image, (int)newSize.x, (int)newSize.y, new NearestNeighborResizer());

							var encoder = new PngEncoder();
							encoder.Encode(newImage, newStream);
							newStream.Position = 0;
						}
					}
					catch (Exception e)
					{
						newStream.Dispose();
						newStream = null;
						Debug.LogError(e.Message);
					}
					finally
					{
						streamLoadedCallback(newStream, true);
					}
				}
			}
			else
			{
				streamLoadedCallback(null, false);
			}
		}
示例#2
0
 public void DeleteFile(string fileName, FolderLocations folderLocation, StreamDeleteCallbackMethod callback)
 {
     if (callback != null)
     {
         callback(false);
     }
 }
示例#3
0
        private async void saveFileDialogAsync(byte[] data, FolderLocations folderLocation, string[] fileTypes, StreamSavedCallbackMethod streamSavedCallback)
        {
            await WinRTPlugin.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async delegate()
            {
                var picker = new FileSavePicker();
                if (fileTypes != null && fileTypes.Length != 0)
                {
                    picker.FileTypeChoices.Add(new KeyValuePair <string, IList <string> >("Supported File Types", fileTypes));
                }

                picker.SuggestedStartLocation = getFolderType(folderLocation);
                var file = await picker.PickSaveFileAsync();
                if (file != null)
                {
                    using (var fileStream = await file.OpenStreamForWriteAsync())
                    {
                        fileStream.Write(data, 0, data.Length);
                        if (streamSavedCallback != null)
                        {
                            streamSavedCallback(true);
                        }
                    }
                }
                else
                {
                    if (streamSavedCallback != null)
                    {
                        streamSavedCallback(false);
                    }
                }
            });
        }
        public void SaveFileDialog(Stream stream, FolderLocations folderLocation, string[] fileTypes, StreamSavedCallbackMethod streamSavedCallback)
        {
            var data = new byte[stream.Length];

            stream.Read(data, 0, data.Length);
            SaveFileDialog(data, folderLocation, fileTypes, streamSavedCallback);
        }
        public void SaveFile(string fileName, Stream stream, FolderLocations folderLocation, StreamSavedCallbackMethod streamSavedCallback)
        {
            var data = new byte[stream.Length];

            stream.Read(data, 0, data.Length);
            SaveFile(fileName, data, folderLocation, streamSavedCallback);
        }
示例#6
0
        public override void SaveFile(string fileName, byte[] data, FolderLocations folderLocation, StreamSavedCallbackMethod steamSavedCallback)
        {
            if (folderLocation == FolderLocations.Pictures)
            {
                using (var file = new FileStream("/accounts/1000/shared/photos/" + fileName, FileMode.Create, FileAccess.Write))
                {
                    file.Write(data, 0, data.Length);
                }

                if (steamSavedCallback != null)
                {
                    steamSavedCallback(true);
                }
            }
            else if (folderLocation != FolderLocations.Storage)
            {
                Debug.LogError("Save file in folder location: " + folderLocation + " is not supported.");
                if (steamSavedCallback != null)
                {
                    steamSavedCallback(false);
                }
            }
            else
            {
                base.SaveFile(fileName, data, folderLocation, steamSavedCallback);
            }
        }
示例#7
0
 public void SaveFile(string fileName, byte[] data, FolderLocations folderLocation, StreamSavedCallbackMethod steamSavedCallback)
 {
     if (steamSavedCallback != null)
     {
         steamSavedCallback(false);
     }
 }
示例#8
0
 public override void SaveFile(string fileName, byte[] data, FolderLocations folderLocation, StreamSavedCallbackMethod steamSavedCallback)
 {
     if (folderLocation == FolderLocations.Pictures)
     {
         streamFileSavedCallback = steamSavedCallback;
         unsafe
         {
             fixed(byte *dataPtr = data)
             {
                 SaveImageStream(dataPtr, data.Length);
             }
         }
     }
     else if (folderLocation != FolderLocations.Storage)
     {
         Debug.LogError("Save file in folder location: " + folderLocation + " is not supported.");
         if (steamSavedCallback != null)
         {
             steamSavedCallback(false);
         }
     }
     else
     {
         base.SaveFile(fileName, data, folderLocation, steamSavedCallback);
     }
 }
示例#9
0
 public void FileExists(string fileName, FolderLocations folderLocation, StreamExistsCallbackMethod callback)
 {
     if (callback != null)
     {
         callback(false);
     }
 }
示例#10
0
 public void LoadFile(string fileName, FolderLocations folderLocation, StreamLoadedCallbackMethod streamLoadedCallback)
 {
     if (streamLoadedCallback != null)
     {
         streamLoadedCallback(null, false);
     }
 }
示例#11
0
 public void LoadFileDialog(FolderLocations folderLocation, int maxWidth, int maxHeight, int x, int y, int width, int height, string[] fileTypes, StreamLoadedCallbackMethod streamLoadedCallback)
 {
     if (streamLoadedCallback != null)
     {
         streamLoadedCallback(null, false);
     }
 }
示例#12
0
        public virtual void LoadFile(string fileName, FolderLocations folderLocation, StreamLoadedCallbackMethod streamLoadedCallback)
        {
            if (streamLoadedCallback == null)
            {
                return;
            }

            MemoryStream stream = null;

            try
            {
                using (var file = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    var data = new byte[file.Length];
                    file.Read(data, 0, data.Length);
                    stream = new MemoryStream(data);
                }
            }
            catch (Exception e)
            {
                if (stream != null)
                {
                    stream.Dispose();
                }
                Debug.LogError(e.Message);
                streamLoadedCallback(null, false);
                return;
            }

            streamLoadedCallback(stream, true);
        }
示例#13
0
 public void SaveFileDialog(byte[] data, FolderLocations folderLocation, string[] fileTypes, StreamSavedCallbackMethod streamSavedCallback)
 {
     if (streamSavedCallback != null)
     {
         streamSavedCallback(false);
     }
 }
示例#14
0
 public virtual void LoadFileDialog(FolderLocations folderLocation, int maxWidth, int maxHeight, int x, int y, int width, int height, string[] fileTypes, StreamLoadedCallbackMethod streamLoadedCallback)
 {
     Debug.LogError("LoadFileDialog not supported on this Platform!");
     if (streamLoadedCallback != null)
     {
         streamLoadedCallback(null, false);
     }
 }
 public void LoadFile(string fileName, FolderLocations folderLocation, StreamLoadedCallbackMethod streamLoadedCallback)
 {
     if (streamLoadedCallback == null)
     {
         return;
     }
     loadFileAsync(fileName, folderLocation, streamLoadedCallback);
 }
 public void LoadFileDialog(FolderLocations folderLocation, int maxWidth, int maxHeight, int x, int y, int width, int height, string[] fileTypes, StreamLoadedCallbackMethod streamLoadedCallback)
 {
     if (streamLoadedCallback == null)
     {
         return;
     }
     loadFileDialogAsync(folderLocation, maxWidth, maxHeight, fileTypes, streamLoadedCallback);
 }
示例#17
0
 public virtual void SaveFileDialog(byte[] data, FolderLocations folderLocation, string[] fileTypes, StreamSavedCallbackMethod streamSavedCallback)
 {
     Debug.LogError("SaveFileDialog not supported on this Platform!");
     if (streamSavedCallback != null)
     {
         streamSavedCallback(false);
     }
 }
示例#18
0
        public override void SaveFileDialog(byte[] data, FolderLocations folderLocation, string[] fileTypes, StreamSavedCallbackMethod streamSavedCallback)
        {
            if (streamSavedCallback == null)
            {
                return;
            }

            // open native dlg
            var file = new OPENFILENAME();

            file.lStructSize = (uint)Marshal.SizeOf(typeof(OPENFILENAME));
            file.hwndOwner   = IntPtr.Zero;
            file.lpstrDefExt = IntPtr.Zero;
            file.lpstrFile   = Marshal.AllocHGlobal((int)MAX_PATH);
            unsafe { ((byte *)file.lpstrFile.ToPointer())[0] = 0; }
            file.nMaxFile        = MAX_PATH;
            file.lpstrFilter     = generateFilterValue(fileTypes);
            file.nFilterIndex    = 0;
            file.lpstrInitialDir = Marshal.StringToHGlobalUni(Application.dataPath);
            file.lpstrTitle      = Marshal.StringToHGlobalUni("Save file");
            file.Flags           = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
            GetSaveFileName(ref file);

            // get native dlg result
            string filename = null;

            if (file.lpstrFile != IntPtr.Zero)
            {
                filename = Marshal.PtrToStringUni(file.lpstrFile);
                Debug.Log("Saving file: " + filename);
            }

            Marshal.FreeHGlobal(file.lpstrFile);
            Marshal.FreeHGlobal(file.lpstrInitialDir);
            Marshal.FreeHGlobal(file.lpstrTitle);
            Marshal.FreeHGlobal(file.lpstrFilter);

            // save file
            if (!string.IsNullOrEmpty(filename))
            {
                using (var stream = new FileStream(filename, FileMode.Create, FileAccess.Write))
                {
                    stream.Write(data, 0, data.Length);
                }

                if (streamSavedCallback != null)
                {
                    streamSavedCallback(true);
                }
            }
            else
            {
                if (streamSavedCallback != null)
                {
                    streamSavedCallback(false);
                }
            }
        }
示例#19
0
		public override void SaveFileDialog(Stream stream, FolderLocations folderLocation, string[] fileTypes, StreamSavedCallbackMethod streamSavedCallback)
		{
			if (streamSavedCallback == null) return;

			var data = new byte[stream.Length];
			stream.Position = 0;
			stream.Read(data, 0, data.Length);
			SaveFileDialog(data, folderLocation, fileTypes, streamSavedCallback);
		}
示例#20
0
        public static Stream SaveFile(string filename, FolderLocations folderLocation)
                #endif
        {
                        #if OSX || iOS
            throw new NotImplementedException();
                        #elif ANDROID
            throw new NotImplementedException();
                        #elif NaCl
            throw new NotImplementedException();
                        #elif WINRT || WP8
            filename = filename.Replace('/', '\\');
            switch (folderLocation)
            {
            case FolderLocations.Application:
                var appFolder = Package.Current.InstalledLocation;
                return(await appFolder.OpenStreamForWriteAsync(filename, CreationCollisionOption.ReplaceExisting));

            case FolderLocations.Storage:
                var storageFolder = ApplicationData.Current.LocalFolder;
                return(await storageFolder.OpenStreamForWriteAsync(filename, CreationCollisionOption.ReplaceExisting));

            case FolderLocations.Documents:
                var docFile = await KnownFolders.DocumentsLibrary.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);

                return(await docFile.OpenStreamForWriteAsync());

            case FolderLocations.Pictures:
                var picFile = await KnownFolders.PicturesLibrary.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);

                return(await picFile.OpenStreamForWriteAsync());

            case FolderLocations.Music:
                var musicFile = await KnownFolders.MusicLibrary.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);

                return(await musicFile.OpenStreamForWriteAsync());

            case FolderLocations.Video:
                var videoFile = await KnownFolders.VideosLibrary.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);

                return(await videoFile.OpenStreamForWriteAsync());

            default:
                Debug.ThrowError("Streams", "Unsuported folder location: " + folderLocation.ToString());
                break;
            }
            return(null);
                        #else
                        #if LINUX
            filename = filename.Replace('\\', '/');
                        #else
            filename = filename.Replace('/', '\\');
                        #endif
            return(new FileStream(filename, FileMode.Create, FileAccess.Write));
                        #endif
        }
示例#21
0
        public static bool FileExists(string filename, FolderLocations folderLocation)
                #endif
        {
                        #if OSX || iOS
            throw new NotImplementedException();
                        #elif ANDROID
            throw new NotImplementedException();
                        #elif NaCl
            throw new NotImplementedException();
                        #elif WINRT || WP8
            filename = filename.Replace('/', '\\');
            try
            {
                switch (folderLocation)
                {
                case FolderLocations.Application:
                    var appFolder = Package.Current.InstalledLocation;
                    return((await appFolder.GetFileAsync(filename)) != null);

                case FolderLocations.Storage:
                    var storageFolder = ApplicationData.Current.LocalFolder;
                    return((await storageFolder.GetFileAsync(filename)) != null);

                case FolderLocations.Documents:
                    return((await KnownFolders.DocumentsLibrary.GetFileAsync(filename)) != null);

                case FolderLocations.Pictures:
                    return((await KnownFolders.PicturesLibrary.CreateFileAsync(filename)) != null);

                case FolderLocations.Music:
                    return((await KnownFolders.MusicLibrary.CreateFileAsync(filename)) != null);

                case FolderLocations.Video:
                    return((await KnownFolders.VideosLibrary.CreateFileAsync(filename)) != null);

                default:
                    Debug.ThrowError("Streams", "Unsuported folder location: " + folderLocation.ToString());
                    break;
                }
            }
            catch
            {
                return(false);
            }
            return(false);
                        #else
                        #if LINUX
            filename = filename.Replace('\\', '/');
                        #else
            filename = filename.Replace('/', '\\');
                        #endif
            throw new NotImplementedException();
                        #endif
        }
示例#22
0
		public void DeleteFile(string fileName, FolderLocations folderLocation, StreamDeleteCallbackMethod callback)
		{
			if (folderLocation != FolderLocations.Storage)
			{
				Debug.LogError("DeleteFile Error: Only Storage folder location is currently supported.");
				callback(false);
				return;
			}

			deleteFileAsync(fileName, callback);
		}
        public void DeleteFile(string fileName, FolderLocations folderLocation, StreamDeleteCallbackMethod callback)
        {
            if (folderLocation != FolderLocations.Storage)
            {
                Debug.LogError("DeleteFile Error: Only Storage folder location is currently supported.");
                callback(false);
                return;
            }

            deleteFileAsync(fileName, callback);
        }
示例#24
0
 public override void LoadFile(string fileName, FolderLocations folderLocation, StreamLoadedCallbackMethod streamLoadedCallback)
 {
     if (folderLocation != FolderLocations.Storage)
     {
         Debug.LogError("Load file in folder location: " + folderLocation + " is not supported.");
         streamLoadedCallback(null, false);
     }
     else
     {
         base.LoadFile(fileName, folderLocation, streamLoadedCallback);
     }
 }
示例#25
0
		public void FileExists(string fileName, FolderLocations folderLocation, StreamExistsCallbackMethod callback)
		{
			if (callback == null) return;
			if (folderLocation != FolderLocations.Storage)
			{
				Debug.LogError("FileExists Error: Only Storage folder location is currently supported.");
				callback(false);
				return;
			}

			fileExistsAsync(fileName, callback);
		}
 public void SaveFileDialog(byte[] data, FolderLocations folderLocation, string[] fileTypes, StreamSavedCallbackMethod streamSavedCallback)
 {
                 #if UNITY_METRO && !UNITY_WP_8_1
     saveFileDialogAsync(data, folderLocation, fileTypes, streamSavedCallback);
                 #else
     Debug.LogError("SaveFileDialog not supported on WP8!");
     if (streamSavedCallback != null)
     {
         streamSavedCallback(false);
     }
                 #endif
 }
示例#27
0
		public override void LoadFile(string fileName, FolderLocations folderLocation, StreamLoadedCallbackMethod streamLoadedCallback)
		{
			if (folderLocation != FolderLocations.Storage)
			{
				Debug.LogError("Load file in folder location: " + folderLocation + " is not supported.");
				streamLoadedCallback(null, false);
			}
			else
			{
				base.LoadFile(fileName, folderLocation, streamLoadedCallback);
			}
		}
示例#28
0
        public override void SaveFileDialog(Stream stream, FolderLocations folderLocation, string[] fileTypes, StreamSavedCallbackMethod streamSavedCallback)
        {
            if (streamSavedCallback == null)
            {
                return;
            }

            var data = new byte[stream.Length];

            stream.Position = 0;
            stream.Read(data, 0, data.Length);
            SaveFileDialog(data, folderLocation, fileTypes, streamSavedCallback);
        }
示例#29
0
 public override void LoadFileDialog(FolderLocations folderLocation, int maxWidth, int maxHeight, int x, int y, int width, int height, string[] fileTypes, StreamLoadedCallbackMethod streamLoadedCallback)
 {
     if (folderLocation != FolderLocations.Pictures)
     {
         Debug.LogError("LoadFileDialog not supported for folder location: " + folderLocation + " on this Platform yet.");
         streamLoadedCallback(null, false);
     }
     else
     {
         streamFileLoadedCallback = streamLoadedCallback;
         LoadImagePicker(maxWidth, maxHeight, x, y, width, height);
     }
 }
示例#30
0
 private static string getCorrectUnityPath(string fileName, FolderLocations folderLocation)
 {
                 #if UNITY_WINRT
     return(ConvertToPlatformSlash(fileName));
                 #else
     if (folderLocation == FolderLocations.Storage)
     {
         return(ConvertToPlatformSlash(Application.persistentDataPath + "/" + fileName));
     }
     else
     {
         return(ConvertToPlatformSlash(fileName));
     }
                 #endif
 }
        public void FileExists(string fileName, FolderLocations folderLocation, StreamExistsCallbackMethod callback)
        {
            if (callback == null)
            {
                return;
            }
            if (folderLocation != FolderLocations.Storage)
            {
                Debug.LogError("FileExists Error: Only Storage folder location is currently supported.");
                callback(false);
                return;
            }

            fileExistsAsync(fileName, callback);
        }
示例#32
0
        public override void LoadFileDialog(FolderLocations folderLocation, int maxWidth, int maxHeight, int x, int y, int width, int height, string[] fileTypes, StreamLoadedCallbackMethod streamLoadedCallback)
        {
            if (folderLocation != FolderLocations.Pictures)
            {
                Debug.LogError("LoadFileDialog not supported for folder location: " + folderLocation + " on this Platform yet.");
                streamLoadedCallback(null, false);
            }
            else
            {
                if (Common.navigator_invoke_invocation_create(ref invoke) != 0)
                {
                    return;
                }
                if (Common.navigator_invoke_invocation_set_target(invoke, "sys.filepicker.target") != 0)                // sys.filesaver.target << use for file save dialog
                {
                    Common.navigator_invoke_invocation_destroy(invoke);
                    return;
                }

                if (Common.navigator_invoke_invocation_set_action(invoke, "bb.action.OPEN") != 0)
                {
                    Common.navigator_invoke_invocation_destroy(invoke);
                    return;
                }

                if (Common.navigator_invoke_invocation_set_type(invoke, "application/vnd.blackberry.file_picker") != 0)
                {
                    Common.navigator_invoke_invocation_destroy(invoke);
                    return;
                }

                if (Common.navigator_invoke_invocation_send(invoke) != 0)
                {
                    Common.navigator_invoke_invocation_destroy(invoke);
                    return;
                }

                var dataPathPatterns = new string[]
                {
                    @"file\://(/accounts/1000/shared/photos/)([\w|\.|\-]*)",
                    @"file\://(/accounts/1000/shared/camera/)([\w|\.|\-]*)",
                    @"file\://(/accounts/1000/shared/downloads/)([\w|\.|\-]*)"
                };
                waitAndProcessImage(addUppers(fileTypes), dataPathPatterns, maxWidth, maxHeight, streamLoadedCallback);

                Common.navigator_invoke_invocation_destroy(invoke);
            }
        }
示例#33
0
        /// <summary>
        /// Use to have to user pic a file on iOS. (Remember to dispose loaded stream)
        /// NOTE: The x, y, width, height is ONLY for iOS (other platforms ignore these values).
        /// </summary>
        /// <param name="folderLocation">Folder location from where the user should choose from.</param>
        /// <param name="maxWidth">Image size returned will not be above the Max Width value (set 0 to disable)</param>
        /// <param name="maxHeight">Image size returned will not be above the Max Height value (set 0 to disable)</param>
        /// <param name="x">iOS iPad dlg X.</param>
        /// <param name="y">iOS iPad dlg Y.</param>
        /// <param name="width">iOS iPad dlg Width.</param>
        /// <param name="height">iOS iPad dlg Height.</param>
        /// <param name="fileTypes">File types the user can see in file popup.</param>
        /// <param name="streamLoadedCallback">The callback that fires when done.</param>
        public static void LoadFileDialog(FolderLocations folderLocation, int maxWidth, int maxHeight, int x, int y, int width, int height, string[] fileTypes, StreamLoadedCallbackMethod streamLoadedCallback)
        {
            if (loadingStream)
            {
                var que = new StreamManagerQue(StreamManagerQueTypes.LoadFileDialog);
                que.streamLoadedCallback = streamLoadedCallback;
                que.FolderLocation       = folderLocation;
                que.FileTypes            = fileTypes;
                ques.Add(que);
                return;
            }

            loadingStream = true;
            StreamManager.streamLoadedCallback = streamLoadedCallback;
            plugin.LoadFileDialog(folderLocation, maxWidth, maxHeight, x, y, width, height, fileTypes, async_streamLoadedCallback);
        }
示例#34
0
        /// <summary>
        /// Use to delete a file.
        /// </summary>
        /// <param name="fileName">FileName to delete.</param>
        /// <param name="folderLocation">Folder location to delete file from.</param>
        /// <param name="streamDeleteCallback">The callback that fires when done.</param>
        public static void DeleteFile(string fileName, FolderLocations folderLocation, StreamDeleteCallbackMethod streamDeleteCallback)
        {
            if (checkingIfFileExists)
            {
                var que = new StreamManagerQue(StreamManagerQueTypes.DeleteFile);
                que.streamDeleteCallback = streamDeleteCallback;
                que.FileName             = fileName;
                que.FolderLocation       = folderLocation;
                ques.Add(que);
                return;
            }

            deletingFile = true;
            StreamManager.streamDeleteCallback = streamDeleteCallback;
            plugin.DeleteFile(getCorrectUnityPath(fileName, folderLocation), folderLocation, async_streamDeleteCallback);
        }
示例#35
0
        /// <summary>
        /// Use to load a file.
        /// </summary>
        /// <param name="fileName">FileName to load.</param>
        /// <param name="folderLocation">Folder location to load from.</param>
        /// <param name="streamLoadedCallback">The callback that fires when done.</param>
        public static void LoadFile(string fileName, FolderLocations folderLocation, StreamLoadedCallbackMethod streamLoadedCallback)
        {
            if (loadingStream)
            {
                var que = new StreamManagerQue(StreamManagerQueTypes.LoadFile);
                que.streamLoadedCallback = streamLoadedCallback;
                que.FileName             = fileName;
                que.FolderLocation       = folderLocation;
                ques.Add(que);
                return;
            }

            loadingStream = true;
            StreamManager.streamLoadedCallback = streamLoadedCallback;
            plugin.LoadFile(getCorrectUnityPath(fileName, folderLocation), folderLocation, async_streamLoadedCallback);
        }
示例#36
0
		public override void SaveFileDialog(byte[] data, FolderLocations folderLocation, string[] fileTypes, StreamSavedCallbackMethod streamSavedCallback)
		{
			if (streamSavedCallback == null) return;

			// open native dlg
			var file = new OPENFILENAME();
			file.lStructSize = (uint)Marshal.SizeOf(typeof(OPENFILENAME));
			file.hwndOwner = IntPtr.Zero;
			file.lpstrDefExt = IntPtr.Zero;
			file.lpstrFile = Marshal.AllocHGlobal((int)MAX_PATH);
			unsafe {((byte*)file.lpstrFile.ToPointer())[0] = 0;}
			file.nMaxFile = MAX_PATH;
			file.lpstrFilter = generateFilterValue(fileTypes);
			file.nFilterIndex = 0;
			file.lpstrInitialDir = Marshal.StringToHGlobalUni(Application.dataPath);
			file.lpstrTitle = Marshal.StringToHGlobalUni("Save file");
			file.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
			GetSaveFileName(ref file);

			// get native dlg result
			string filename = null;
			if (file.lpstrFile != IntPtr.Zero)
			{
				filename = Marshal.PtrToStringUni(file.lpstrFile);
				Debug.Log("Saving file: " + filename);
			}

			Marshal.FreeHGlobal(file.lpstrFile);
			Marshal.FreeHGlobal(file.lpstrInitialDir);
			Marshal.FreeHGlobal(file.lpstrTitle);
			Marshal.FreeHGlobal(file.lpstrFilter);

			// save file
			if (!string.IsNullOrEmpty(filename))
			{
				using (var stream = new FileStream(filename, FileMode.Create, FileAccess.Write))
				{
					stream.Write(data, 0, data.Length);
				}

				if (streamSavedCallback != null) streamSavedCallback(true);
			}
			else
			{
				if (streamSavedCallback != null) streamSavedCallback(false);
			}
		}
示例#37
0
		public override void SaveFile(string fileName, byte[] data, FolderLocations folderLocation, StreamSavedCallbackMethod steamSavedCallback)
		{
			if (folderLocation == FolderLocations.Pictures)
			{
				streamFileSavedCallback = steamSavedCallback;
				native.CallStatic("SaveImage", data, Path.GetFileNameWithoutExtension(fileName), "");
			}
			else if (folderLocation != FolderLocations.Storage)
			{
				Debug.LogError("Save file in folder location: " + folderLocation + " is not supported.");
				if (steamSavedCallback != null) steamSavedCallback(false);
			}
			else
			{
				base.SaveFile(fileName, data, folderLocation, steamSavedCallback);
			}
		}
示例#38
0
		public override void SaveFileDialog(byte[] data, FolderLocations folderLocation, string[] fileTypes, StreamSavedCallbackMethod streamSavedCallback)
		{
			string fileName = EditorUtility.SaveFilePanel("Save file", "", "FileName", generateFilterValue(fileTypes));
			if (!string.IsNullOrEmpty(fileName))
			{
				using (var stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
				{
					stream.Write(data, 0, data.Length);
				}

				if (streamSavedCallback != null) streamSavedCallback(true);
			}
			else
			{
				if (streamSavedCallback != null) streamSavedCallback(false);
			}
		}
		public virtual void SaveFile(string fileName, byte[] data, FolderLocations folderLocation, StreamSavedCallbackMethod steamSavedCallback)
		{
			try
			{
				using (var file = new FileStream(fileName, FileMode.Create, FileAccess.Write))
				{
					file.Write(data, 0, data.Length);
				}
			}
			catch (Exception e)
			{
				Debug.LogError(e.Message);
				if(steamSavedCallback != null) steamSavedCallback(false);
				return;
			}

			if(steamSavedCallback != null) steamSavedCallback(true);
		}
示例#40
0
		public override void SaveFile(string fileName, byte[] data, FolderLocations folderLocation, StreamSavedCallbackMethod steamSavedCallback)
		{
			if (folderLocation == FolderLocations.Pictures)
			{
				using (var file = new FileStream("/accounts/1000/shared/photos/"+fileName, FileMode.Create, FileAccess.Write))
				{
					file.Write(data, 0, data.Length);
				}
					
				if(steamSavedCallback != null) steamSavedCallback(true);
			}
			else if (folderLocation != FolderLocations.Storage)
			{
				Debug.LogError("Save file in folder location: " + folderLocation + " is not supported.");
				if (steamSavedCallback != null) steamSavedCallback(false);
			}
			else
			{
				base.SaveFile(fileName, data, folderLocation, steamSavedCallback);
			}
		}
		public void DeleteFile(string fileName, FolderLocations folderLocation, StreamDeleteCallbackMethod callback)
		{
			if (folderLocation != FolderLocations.Storage)
			{
				Debug.LogError("DeleteFile Error: Only Storage folder location is currently supported.");
				callback(false);
				return;
			}

			try
			{
				File.Delete(fileName);
			}
			catch (Exception e)
			{
				Debug.LogError("DeleteFile Error: " + e.Message);
				callback(false);
				return;
			}

			callback(true);
		}
		public virtual void LoadFile(string fileName, FolderLocations folderLocation, StreamLoadedCallbackMethod streamLoadedCallback)
		{
			if (streamLoadedCallback == null) return;

			MemoryStream stream = null;
			try
			{
				using (var file = new FileStream(fileName, FileMode.Open, FileAccess.Read))
				{
					var data = new byte[file.Length];
					file.Read(data, 0, data.Length);
					stream = new MemoryStream(data);
				}
			}
			catch (Exception e)
			{
				if (stream != null) stream.Dispose();
				Debug.LogError(e.Message);
				streamLoadedCallback(null, false);
				return;
			}

			streamLoadedCallback(stream, true);
		}
示例#43
0
		public void SaveFileDialog(Stream stream, FolderLocations folderLocation, string[] fileTypes, StreamSavedCallbackMethod streamSavedCallback)
		{
			var data = new byte[stream.Length];
			stream.Read(data, 0, data.Length);
			SaveFileDialog(data, folderLocation, fileTypes, streamSavedCallback);
		}
示例#44
0
		public void FileExists(string fileName, FolderLocations folderLocation, StreamExistsCallbackMethod callback)
		{
			Native.FileExists(fileName, folderLocation, callback);
		}
示例#45
0
		public void DeleteFile(string fileName, FolderLocations folderLocation, StreamDeleteCallbackMethod callback)
		{
			Native.DeleteFile(fileName, folderLocation, callback);
		}
示例#46
0
		private async void loadFileDialogAsync(FolderLocations folderLocation, int maxWidth, int maxHeight, string[] fileTypes, StreamLoadedCallbackMethod streamLoadedCallback)
		#endif
		{
			#if WINDOWS_PHONE
			WinRTPlugin.Dispatcher.BeginInvoke(async delegate()
			#elif UNITY_WP_8_1
			await WinRTPlugin.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, delegate()
			#else
			await WinRTPlugin.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async delegate()
			#endif
			{
				Stream stream = null;
				try
				{
					#if WINDOWS_PHONE
					if (folderLocation == FolderLocations.Pictures)
					{
						photoChooser = new PhotoChooserTask();
						photoChooser.ShowCamera = false;
						photoChooser.Completed += photoChooserTask_Completed;
						photoChooserTask_StreamLoadedCallback = streamLoadedCallback;
						photoChooserTask_fileTypes = fileTypes;
						photoChooserTask_maxWidth = maxWidth;
						photoChooserTask_maxHeight = maxHeight;
						photoChooser.Show();
						return;
					}
					#endif

					var picker = new FileOpenPicker();
					if (fileTypes != null)
					{
						foreach (var fileType in fileTypes) picker.FileTypeFilter.Add(fileType);
					}

					picker.SuggestedStartLocation = getFolderType(folderLocation);
					#if UNITY_WP_8_1
					LoadFileDialog_picker = picker;
					LoadFileDialog_streamLoadedCallback = streamLoadedCallback;
					LoadFileDialog_maxWidth = maxWidth;
					LoadFileDialog_maxHeight = maxHeight;
					picker.PickSingleFileAndContinue();
					#else
					var file = await picker.PickSingleFileAsync();
					if (file != null)
					{
						if (maxWidth == 0 || maxHeight == 0)
						{
							stream = await file.OpenStreamForReadAsync();
							ReignServices.InvokeOnUnityThread(delegate
							{
								streamLoadedCallback(stream, true);
							});
						}
						else
						{
							#if UNITY_METRO
							using (var tempStream = await file.OpenStreamForReadAsync())
							{
								#if UNITY_METRO_8_0
								using (var outputStream = new MemoryStream().AsOutputStream())
								{
									await RandomAccessStream.CopyAsync(tempStream.AsInputStream(), outputStream);
									stream = await resizeImageStream((IRandomAccessStream)outputStream, maxWidth, maxHeight);
								}
								#else
								stream = await resizeImageStream(tempStream.AsRandomAccessStream(), maxWidth, maxHeight);
								#endif
							}

							ReignServices.InvokeOnUnityThread(delegate
							{
								streamLoadedCallback(stream, true);
							});
							#endif
						}
					}
					else
					{
						ReignServices.InvokeOnUnityThread(delegate
						{
							streamLoadedCallback(null, false);
						});
					}
					#endif
				}
				catch (Exception e)
				{
					if (stream != null) stream.Dispose();
					Debug.LogError(e.Message);
					ReignServices.InvokeOnUnityThread(delegate
					{
						streamLoadedCallback(null, false);
					});
				}
			});
		}
示例#47
0
		private PickerLocationId getFolderType(FolderLocations folderLocation)
		{
			PickerLocationId folder = PickerLocationId.Desktop;
			switch (folderLocation)
			{
				case FolderLocations.Documents: folder = PickerLocationId.DocumentsLibrary; break;
				case FolderLocations.Pictures: folder = PickerLocationId.PicturesLibrary; break;
				case FolderLocations.Music: folder = PickerLocationId.MusicLibrary; break;
				case FolderLocations.Video: folder = PickerLocationId.VideosLibrary; break;
				default: Debug.LogError("Unsuported folder location: " + folderLocation); break;
			}

			return folder;
		}
示例#48
0
		public void SaveFile(string fileName, Stream stream, FolderLocations folderLocation, StreamSavedCallbackMethod streamSavedCallback)
		{
			var data = new byte[stream.Length];
			stream.Read(data, 0, data.Length);
			SaveFile(fileName, data, folderLocation, streamSavedCallback);
		}
示例#49
0
		private void loadFileDialogAsync(FolderLocations folderLocation, int maxWidth, int maxHeight, string[] fileTypes, StreamLoadedCallbackMethod streamLoadedCallback)
示例#50
0
		private async void saveFileAsync(string fileName, byte[] data, FolderLocations folderLocation, StreamSavedCallbackMethod streamSavedCallback)
		{
			try
			{
				#if WINDOWS_PHONE
				if (folderLocation == FolderLocations.Pictures)
				{
					using (var m = new MediaLibrary())
					using (var image = m.SavePicture(fileName, data))
					{
						if (streamSavedCallback != null) streamSavedCallback(image != null);
					}
					return;
				}
				#endif
				
				fileName = fileName.Replace('/', '\\');
				using (var stream = await saveStream(fileName, folderLocation))
				{
					stream.Write(data, 0, data.Length);
				}
			}
			catch (Exception e)
			{
				Debug.LogError(e.Message);
				if (streamSavedCallback != null) streamSavedCallback(false);
				return;
			}

			if (streamSavedCallback != null) streamSavedCallback(true);
		}
示例#51
0
		public void LoadFileDialog(FolderLocations folderLocation, int maxWidth, int maxHeight, int x, int y, int width, int height, string[] fileTypes, StreamLoadedCallbackMethod streamLoadedCallback)
		{
			if (streamLoadedCallback == null) return;
			loadFileDialogAsync(folderLocation, maxWidth, maxHeight, fileTypes, streamLoadedCallback);
		}
示例#52
0
		public void SaveFileDialog(byte[] data, FolderLocations folderLocation, string[] fileTypes, StreamSavedCallbackMethod streamSavedCallback)
		{
			Native.SaveFileDialog(data, folderLocation, fileTypes, streamSavedCallback);
		}
示例#53
0
		public void SaveFile(string fileName, byte[] data, FolderLocations folderLocation, StreamSavedCallbackMethod streamSavedCallback)
		{
			Native.SaveFile(fileName, data, folderLocation, streamSavedCallback);
		}
示例#54
0
		private async void loadFileAsync(string fileName, FolderLocations folderLocation, StreamLoadedCallbackMethod streamLoadedCallback)
		{
			Stream stream = null;
			try
			{
				#if WINDOWS_PHONE
				if (folderLocation == FolderLocations.Pictures)
				{
					using (var m = new MediaLibrary())
					{
						foreach (var p in m.Pictures)
						{
							if (p.Name == fileName)
							{
								streamLoadedCallback(p.GetImage(), true);
								p.Dispose();
								return;
							}
							else
							{
								p.Dispose();
							}
						}
					}

					streamLoadedCallback(null, false);
					return;
				}
				#endif

				fileName = fileName.Replace('/', '\\');
				stream = await openStream(fileName, folderLocation);
			}
			catch (Exception e)
			{
				if (stream != null) stream.Dispose();
				Debug.LogError(e.Message);
				streamLoadedCallback(null, false);
				return;
			}

			streamLoadedCallback(stream, stream != null);
		}
示例#55
0
		private async Task<Stream> openStream(string fileName, FolderLocations folderLocation)
		{
			switch (folderLocation)
			{
				case FolderLocations.Application:
					var appFolder = Package.Current.InstalledLocation;
					return await appFolder.OpenStreamForReadAsync(fileName);

				case FolderLocations.Storage:
					var storageFolder = ApplicationData.Current.LocalFolder;
					return await storageFolder.OpenStreamForReadAsync(fileName);

				case FolderLocations.Documents:
					var docFile = await KnownFolders.DocumentsLibrary.GetFileAsync(fileName);
					return await docFile.OpenStreamForReadAsync();

				case FolderLocations.Pictures:
					var picFile = await KnownFolders.PicturesLibrary.GetFileAsync(fileName);
					return await picFile.OpenStreamForReadAsync();

				case FolderLocations.Music:
					var musicFile = await KnownFolders.MusicLibrary.GetFileAsync(fileName);
					return await musicFile.OpenStreamForReadAsync();

				case FolderLocations.Video:
					var videoFile = await KnownFolders.VideosLibrary.GetFileAsync(fileName);
					return await videoFile.OpenStreamForReadAsync();

				default:
					Debug.LogError("Unsuported folder location: " + folderLocation);
					return null;
			}
		}
示例#56
0
		public void LoadFile(string fileName, FolderLocations folderLocation, StreamLoadedCallbackMethod streamLoadedCallback)
		{
			if (streamLoadedCallback == null) return;
			loadFileAsync(fileName, folderLocation, streamLoadedCallback);
		}
示例#57
0
		public void LoadFile(string fileName, FolderLocations folderLocation, StreamLoadedCallbackMethod streamLoadedCallback)
		{
			Native.LoadFile(fileName, folderLocation, streamLoadedCallback);
		}
示例#58
0
		public void SaveFileDialog(byte[] data, FolderLocations folderLocation, string[] fileTypes, StreamSavedCallbackMethod streamSavedCallback)
		{
			#if UNITY_METRO && !UNITY_WP_8_1
			saveFileDialogAsync(data, folderLocation, fileTypes, streamSavedCallback);
			#else
			Debug.LogError("SaveFileDialog not supported on WP8!");
			if (streamSavedCallback != null) streamSavedCallback(false);
			#endif
		}
示例#59
0
		public void LoadFileDialog(FolderLocations folderLocation, int maxWidth, int maxHeight, int x, int y, int width, int height, string[] fileTypes, StreamLoadedCallbackMethod streamLoadedCallback)
		{
			Native.LoadFileDialog(folderLocation, maxWidth, maxHeight, x, y, width, height, fileTypes, streamLoadedCallback);
		}
示例#60
0
		private async void saveFileDialogAsync(byte[] data, FolderLocations folderLocation, string[] fileTypes, StreamSavedCallbackMethod streamSavedCallback)
		{
			await WinRTPlugin.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async delegate()
			{
				var picker = new FileSavePicker();
				if (fileTypes != null && fileTypes.Length != 0)
				{
					picker.FileTypeChoices.Add(new KeyValuePair<string,IList<string>>("Supported File Types", fileTypes));
				}

				picker.SuggestedStartLocation = getFolderType(folderLocation);
				var file = await picker.PickSaveFileAsync();
				if (file != null)
				{
					using (var fileStream = await file.OpenStreamForWriteAsync())
					{
						fileStream.Write(data, 0, data.Length);
						ReignServices.InvokeOnUnityThread(delegate
						{
							if (streamSavedCallback != null) streamSavedCallback(true);
						});
					}
				}
				else
				{
					ReignServices.InvokeOnUnityThread(delegate
					{
						if (streamSavedCallback != null) streamSavedCallback(false);
					});
				}
			});
		}