Ejemplo n.º 1
0
 public OtherSettings(ClipPageList clipPages)
 {
     InitializeComponent();
     this.clipPages         = clipPages;
     HotkeyButton.Info      = clipPages.StopHotkeyInfo;
     AutostartBox.IsChecked = clipPages.AutoStart;
     initializing           = false;
 }
Ejemplo n.º 2
0
        public static void SaveClipPages(ClipPageList clipPages, string path = null)
        {
            path ??= System.IO.Path.Combine(GetAssemblyPath(), Path);

#if DEBUG
            string json = JsonConvert.SerializeObject(clipPages, Formatting.Indented);
#else
            string json = JsonConvert.SerializeObject(clipPages);
#endif

            File.WriteAllText(path, json);
        }
Ejemplo n.º 3
0
        public static ClipPageList GetClipPages(string path = null, bool autoSave = true)
        {
            path ??= System.IO.Path.Combine(GetAssemblyPath(), Path);

            if (!File.Exists(path))
            {
                ClipPageList list = new ClipPageList();
                if (autoSave)
                {
                    list.OnChanged += Pages_OnChanged;
                }
                return(list);
            }

            string json = File.ReadAllText(path);

            if (string.IsNullOrEmpty(json))
            {
                ClipPageList list = new ClipPageList();
                if (autoSave)
                {
                    list.OnChanged += Pages_OnChanged;
                }
                return(list);
            }

            deserializing = true;

            ClipPageList pages = JsonConvert.DeserializeObject <ClipPageList>(json);



            if (autoSave)
            {
                pages.OnChanged += Pages_OnChanged;
            }

            deserializing = false;
            return(pages);
        }
Ejemplo n.º 4
0
        public MainWindow()
        {
#if !DEBUG
            Hide();
#endif

            var    assembly     = Assembly.GetExecutingAssembly();
            string resourceName = "WPF_Soundboard.Resources.icon.ico";

            using Stream stream    = assembly.GetManifestResourceStream(resourceName);
            notifyIcon.Icon        = new Icon(stream);
            notifyIcon.Visible     = true;
            notifyIcon.MouseClick += NotifyIcon_MouseClick;

            notifyIcon.ContextMenuStrip = new ContextMenuStrip();
            var showItem = new ToolStripMenuItem("Show");
            showItem.Click += ShowItem_Click;
            var exitItem = new ToolStripMenuItem("Exit");
            exitItem.Click += ExitItem_Click;
            notifyIcon.ContextMenuStrip.Items.Add(showItem);
            notifyIcon.ContextMenuStrip.Items.Add(exitItem);


            InitializeComponent();

            try
            {
                AudioHandler.Initialize();
            }
            catch
            {
                try
                {
                    MessageBoxResult result = System.Windows.MessageBox.Show("Error while initializing Audio. Do you want to reset audio settings?",
                                                                             "Audio error in WPF-Soundboard",
                                                                             MessageBoxButton.YesNo,
                                                                             MessageBoxImage.Error);

                    if (result == MessageBoxResult.Yes)
                    {
                        AudioHandler.Config = AudioConfig.GetDefault();
                        AudioHandler.Initialize();
                    }
                    else
                    {
                        throw;
                    }
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show(e.GetType() + ": " + e.Message + "\n--------\n" + e.StackTrace, "Audio error in WPF-Soundboard - Quitting", MessageBoxButton.OK, MessageBoxImage.Error);

                    closing            = true;
                    notifyIcon.Visible = false;
                    AudioHandler.Dispose();
                    System.Windows.Application.Current.Shutdown();
                    return;
                }
            }

            clipPages = Serializer.GetClipPages();
            clipPages.GlobalHotkeyList.OnHotkeyPressed += GlobalHotkeyList_OnHotkeyPressed;
            clipPages.OnStopHotkeyPressed += ClipPages_OnStopHotkeyPressed;

            if (clipPages.Count == 0)
            {
                clipPages.Add(new ClipPage(7, 5));
            }

            foreach (ClipPage page in clipPages)
            {
                page.OnChanged       += Page_OnChanged;
                page.OnHotkeyPressed += Page_OnHotkeyPressed;
            }

            currentPage = clipPages[0];
            BuildClipPage();
            UpdatePagesList();
        }