Ejemplo n.º 1
0
        public bool DisplayWarning(Window sender, bool dispatcher = false)
        {
            if (State != PortWarningType.Show)
            {
                return(false);
            }

            State = PortWarningType.Done;

            Action DisplayMessage = async() => {
                if (await MessageWindow.Create(message, new string[] { action, "OK" }, sender) == action)
                {
                    App.URL(url);
                }

                Launchpad.DisplayWarnings(sender);
            };

            if (dispatcher)
            {
                Dispatcher.UIThread.Post(DisplayMessage, DispatcherPriority.MinValue);
            }
            else
            {
                DisplayMessage.Invoke();
            }

            return(true);
        }
Ejemplo n.º 2
0
 async Task <bool> ShouldRemove() => await MessageWindow.Create(
     $"An error occurred while locating the file.\n\n" +
     "You may not have sufficient privileges to read from the destination folder, or\n" +
     "the file you're attempting to locate has been moved.\n\n" +
     "Would you like to remove it from the Recent Projects list?",
     new string[] { "Yes", "No" }, (Window)this.GetVisualRoot()
     ) == "Yes";
Ejemplo n.º 3
0
        public static async Task <bool> ShouldUpdate()
        {
            if (UpdateChecked)
            {
                return(false);
            }

            if (release == null)
            {
                try {
                    await LatestRelease();
                } catch {
                    return(false);
                }
            }

            UpdateChecked = true;

            if (Preferences.CheckForUpdates && release.Name != Program.Version && download != null)
            {
                return(await MessageWindow.Create(
                           $"A new version of Apollo Studio is available ({release.Name} - {download.Size.Bytes().Humanize("#.##")}).\n\n" +
                           "Do you want to update to the latest version?",
                           new string[] { "Yes", "No" }, null
                           ) == "Yes");
            }

            return(false);
        }
Ejemplo n.º 4
0
        public bool DisplayWarning(Window sender, bool dispatcher = false)
        {
            if (State != PortWarningType.Show)
            {
                return(false);
            }

            State = PortWarningType.Done;

            Action DisplayMessage = async() => {
                string[] actions = options.Select(i => i.action).ToArray();
                int      result;

                if ((result = Array.IndexOf(actions, await MessageWindow.Create(message, actions.Append("Ignore").ToArray(), sender))) != -1)
                {
                    App.URL(options[result].url);
                }

                Launchpad.DisplayWarnings(sender);
            };

            if (dispatcher)
            {
                Dispatcher.UIThread.Post(DisplayMessage, DispatcherPriority.MinValue);
            }
            else
            {
                DisplayMessage.Invoke();
            }

            return(true);
        }
Ejemplo n.º 5
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            // Create message window
            msgwin = MessageWindow.Create(new MessageWindowProc(WindowProc));

            // Hook clipboard
            next_window = User.SetClipboardViewer(msgwin.Handle);
        }
Ejemplo n.º 6
0
        public async void Import(int right, string path = null)
        {
            Window sender = Track.Get(_chain).Window;

            if (path == null)
            {
                OpenFileDialog ofd = new OpenFileDialog()
                {
                    AllowMultiple = false,
                    Filters       = new List <FileDialogFilter>()
                    {
                        new FileDialogFilter()
                        {
                            Extensions = new List <string>()
                            {
                                "apdev"
                            },
                            Name = "Apollo Device Preset"
                        }
                    },
                    Title = "Import Device Preset"
                };

                string[] result = await ofd.ShowAsync(sender);

                if (result.Length > 0)
                {
                    path = result[0];
                }
                else
                {
                    return;
                }
            }

            Copyable loaded;

            try {
                using (FileStream file = File.Open(path, FileMode.Open, FileAccess.Read))
                    loaded = await Decoder.Decode(file, typeof(Copyable));
            } catch {
                await MessageWindow.Create(
                    $"An error occurred while reading the file.\n\n" +
                    "You may not have sufficient privileges to read from the destination folder, or\n" +
                    "the file you're attempting to read is invalid.",
                    null, sender
                    );

                return;
            }

            Copyable_Insert(loaded, right, true);
        }
Ejemplo n.º 7
0
        public static void CFWError(Window sender)
        {
            CFWIncompatible = CFWIncompatibleState.Done;

            Dispatcher.UIThread.Post(async() => await MessageWindow.Create(
                                         "One or more connected Launchpad Pros are running an older version of the\n" +
                                         "performance-optimized custom firmware which is not compatible with\n" +
                                         "Apollo Studio.\n\n" +
                                         "Update these to the latest version of the firmware or switch back to stock\n" +
                                         "firmware to use them with Apollo Studio.",
                                         null, sender
                                         ), DispatcherPriority.MinValue);
        }
Ejemplo n.º 8
0
        public async void Export(int left, int right)
        {
            Window sender = Track.Get(_chain).Window;

            SaveFileDialog sfd = new SaveFileDialog()
            {
                Filters = new List <FileDialogFilter>()
                {
                    new FileDialogFilter()
                    {
                        Extensions = new List <string>()
                        {
                            "apdev"
                        },
                        Name = "Apollo Device Preset"
                    }
                },
                Title = "Export Device Preset"
            };

            string result = await sfd.ShowAsync(sender);

            if (result != null)
            {
                string[] file = result.Split(Path.DirectorySeparatorChar);

                if (Directory.Exists(string.Join("/", file.Take(file.Count() - 1))))
                {
                    Copyable copy = new Copyable();

                    for (int i = left; i <= right; i++)
                    {
                        copy.Contents.Add(_chain[i]);
                    }

                    try {
                        File.WriteAllBytes(result, Encoder.Encode(copy).ToArray());
                    } catch (UnauthorizedAccessException) {
                        await MessageWindow.Create(
                            $"An error occurred while writing the file.\n\n" +
                            "You may not have sufficient privileges to write to the destination folder, or\n" +
                            "the current file already exists but cannot be overwritten.",
                            null, sender
                            );
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public static async Task <Copyable> DecodeFile(string path, Window sender)
        {
            try {
                using (FileStream file = File.Open(path, FileMode.Open, FileAccess.Read))
                    return(await Decoder.Decode(file, typeof(Copyable)));
            } catch {
                await MessageWindow.Create(
                    $"An error occurred while reading the file.\n\n" +
                    "You may not have sufficient privileges to read from the destination folder, or\n" +
                    "the file you're attempting to read is invalid.",
                    null, sender
                    );

                return(null);
            }
        }
Ejemplo n.º 10
0
        public static async Task <dynamic> Decode(Stream input, Type ensure)
        {
            using (BinaryReader reader = new BinaryReader(input)) {
                if (!DecodeHeader(reader))
                {
                    throw new InvalidDataException();
                }

                int version = reader.ReadInt32();

                if (version > Common.version && await MessageWindow.Create(
                        "The content you're attempting to read was created with a newer version of\n" +
                        "Apollo Studio, which might result in it not loading correctly.\n\n" +
                        "Are you sure you want to proceed?",
                        new string[] { "Yes", "No" }, null
                        ) == "No")
                {
                    throw new InvalidDataException();
                }

                return(Decode(reader, version, ensure, true));
            }
        }
Ejemplo n.º 11
0
        async void ContextMenu_Click(object sender, EventArgs e)
        {
            Window root = (Window)this.GetVisualRoot();

            root.Focus();

            IInteractive item = ((RoutedEventArgs)e).Source;

            if (item is MenuItem selected)
            {
                bool remove = (string)selected.Header == "Remove";

                if ((string)selected.Header == "Open Containing Folder")
                {
                    if (File.Exists(_path))
                    {
                        Showed?.Invoke(Path.GetDirectoryName(_path));
                    }
                    else
                    {
                        remove |= await MessageWindow.Create(
                            $"An error occurred while locating the file.\n\n" +
                            "You may not have sufficient privileges to read from the destination folder, or\n" +
                            "the file you're attempting to locate has been moved.\n\n" +
                            "Would you like to remove it from the Recent Projects list?",
                            new string[] { "Yes", "No" }, root
                            ) == "Yes";
                    }
                }

                if (remove)
                {
                    Removed?.Invoke(this, _path);
                }
            }
        }
Ejemplo n.º 12
0
        async void MouseUp(object sender, PointerReleasedEventArgs e)
        {
            if (mouseHeld)
            {
                if (e.MouseButton == MouseButton.Left)
                {
                    bool remove = false;

                    if (File.Exists(_path))
                    {
                        Opened?.Invoke(_path);
                    }
                    else
                    {
                        remove = await MessageWindow.Create(
                            $"An error occurred while locating the file.\n\n" +
                            "You may not have sufficient privileges to read from the destination folder, or\n" +
                            "the file you're attempting to locate has been moved.\n\n" +
                            "Would you like to remove it from the Recent Projects list?",
                            new string[] { "Yes", "No" }, (Window)this.GetVisualRoot()
                            ) == "Yes";
                    }

                    if (remove)
                    {
                        Removed?.Invoke(this, _path);
                    }
                }
                else if (e.MouseButton == MouseButton.Right)
                {
                    InfoContextMenu.Open((Control)sender);
                }

                mouseHeld = false;
            }
        }