Ejemplo n.º 1
0
        private static FourOptionsDialog InitDuplicateDialog()
        {
            FourOptionsDialog dialog = new FourOptionsDialog();

            dialog.Message              = "This deck already has a media file with the same name.\n ";
            dialog.Title                = "Duplicate File Name";
            dialog.FirstButton.Content  = "Replace";
            dialog.SecondButton.Content = "Rename";
            dialog.ThirdButton.Content  = "Reuse";
            return(dialog);
        }
Ejemplo n.º 2
0
        private async Task <string> TryAddNewFileIntoDeckIdMediaFolder(StorageFile file)
        {
            if (!IsMediaFileType(file))
            {
                await UIHelper.ShowMessageDialog("Unsupported file format!", "Error!");

                return(null);
            }

            bool   isCancel  = false;
            bool   isReuse   = false;
            bool   isReplace = false;
            string legalName = collection.Media.StripIllegal(file.Name);
            var    existItem = await deckIdFolder.TryGetItemAsync(legalName) as StorageFile;

            if (existItem != null)
            {
                FourOptionsDialog dialog = InitDuplicateDialog();
                dialog.OpenButtonClicked += async(s, e) => { await Windows.System.Launcher.LaunchFileAsync(existItem); };
                await dialog.ShowAsync();

                isCancel = dialog.IsFourthButtonClick();
                if (isCancel)
                {
                    return(null);
                }

                isReplace = dialog.IsFirstButtonClick();
                isReuse   = dialog.IsThirdButtonClick();
            }

            if (!isReuse && !isReplace)
            {
                legalName = await AddNewFile(file);
            }
            else if (isReplace)
            {
                if (!existItem.IsEqual(file))
                {
                    await file.CopyAndReplaceAsync(existItem);

                    collection.Media.MarkFileAddIntoDatabase(existItem.Name, currentDeckId);
                }
            }

            return(legalName);
        }