Beispiel #1
0
    public void DoExport()
    {
        DisableUI();

        var name        = InstructionManager.Instance.Instruction.Name;
        var pathToSave  = Application.persistentDataPath;
        var pathToMedia = Path.Combine(Application.persistentDataPath, "media");

#if !UNITY_EDITOR
        SaveFileAsync(name, pathToSave, pathToMedia);
#else
        ShowWaitingDialog();
        ExportCompleted?.Invoke(this, true);
        ChangeWaitingDialogText();
        EnableUI();
#endif
    }
        public virtual async Task ExportFileAsync(Scene scene, string filePath, bool overwrite)
        {
            filePath = CorrectFilePath(filePath);

            if (File.Exists(filePath) && overwrite)
            {
                File.Delete(filePath);
                _logger?.LogInformation("File {FilePath} deleted successfully", filePath);
            }

            await ExportFileImpl(scene, filePath).ConfigureAwait(false);

            var fi = new FileInfo(filePath);

            ExportCompleted?.Invoke(this, fi);

            _logger?.LogInformation("{Ext} file {FilePath} ({Size}) generated successfully",
                                    Path.GetExtension(filePath), filePath, Utils.BytesToString(fi.Length));
        }
Beispiel #3
0
    private async void SaveFileAsync(string fileName, string pathToSave, string pathToMedia)
    {
        UnityEngine.WSA.Application.InvokeOnUIThread(async() =>
        {
            FileSavePicker savePicker         = new FileSavePicker();
            savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;

            // Dropdown of file types the user can save the file as
            savePicker.FileTypeChoices.Add("Archieved Expert Data with Media", new List <string>()
            {
                ".zip"
            });

            // Default file name if the user does not type one in or select a file to replace
            savePicker.SuggestedFileName = fileName + ".zip";

            StorageFile file = await savePicker.PickSaveFileAsync();

            if (file != null)
            {
                InstructionManager.Instance.Instruction.Name = file.DisplayName;
                InstructionManager.Instance.Save(true, pathToSave);

                ShowWaitingDialog();
                using (Stream zipFileToSave = await file.OpenStreamForWriteAsync())
                {
                    // do export async
                    await Task.Run(() =>
                    {
                        //open acces to zip file
                        //todo: check mode
                        using (ZipArchive archive = new ZipArchive(zipFileToSave, ZipArchiveMode.Update))
                        {
                            archive.CreateEntryFromFile(Path.Combine(pathToSave, InstructionManager.Instance.Instruction.Name + ".save"), InstructionManager.Instance.Instruction.Name + ".save");

                            foreach (var step in InstructionManager.Instance.Instruction.Steps)
                            {
                                foreach (var mediaFile in step.MediaFiles)
                                {
                                    archive.CreateEntryFromFile(Path.Combine(pathToMedia, mediaFile.FileName), @"media\" + mediaFile.FileName);
                                }
                            }
                        }
                    });
                }

                // the other app can update the remote version of the file.
                // Completing updates may require Windows to ask for user input.
                Windows.Storage.Provider.FileUpdateStatus status =
                    await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file);
                if (status == Windows.Storage.Provider.FileUpdateStatus.Complete)
                {
                    ExportCompleted?.Invoke(this, true);
                }
                else
                {
                    ExportCompleted?.Invoke(this, false);
                }
            }
            else
            {
                ExportCompleted?.Invoke(this, false);
            }

            ChangeWaitingDialogText();
            //EnableUI();
        }, false);
    }
Beispiel #4
0
 /// <summary>
 /// Raises the ExportCompleted event
 /// </summary>
 /// <param name="e">ExportCompleteArgs</param>
 protected virtual void OnExportCompleted(ExportCompleteArgs e)
 {
     ExportCompleted?.Invoke(this, e);
 }