Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        public static void CloseApplication()
        {
            Application.Exit();

            try
            {
                InstrumentManager.InstExclusiveLockObject.EnterReadLock();

                var so = JsonConvert.SerializeObject(SaveEnvironmentSettings(), Formatting.Indented, JsonAutoSettings);
                Settings.Default.EnvironmentSettings = StringCompressionUtility.Compress(so);
                Settings.Default.Save();
            }
            finally
            {
                InstrumentManager.InstExclusiveLockObject.ExitReadLock();
            }
        }
Exemplo n.º 2
0
        unsafe public static void LoadData(byte *data, int length)
        {
            try
            {
                string text = StringCompressionUtility.Decompress(Encoding.Unicode.GetString(data, length));
                InstrumentManager.ClearAllInstruments();
                var settings = JsonConvert.DeserializeObject <EnvironmentSettings>(text, Program.JsonAutoSettings);
                InstrumentManager.RestoreSettings(settings);
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(Exception))
                {
                    throw;
                }
                else if (ex.GetType() == typeof(SystemException))
                {
                    throw;
                }

                MessageBox.Show(ex.ToString());
            }
        }
Exemplo n.º 3
0
        unsafe public static int SaveData(void **saveBuf)
        {
            try
            {
                InstrumentManager.InstExclusiveLockObject.EnterReadLock();

                var    es   = Program.SaveEnvironmentSettings();
                string data = JsonConvert.SerializeObject(es, Formatting.Indented, Program.JsonAutoSettings);
                byte[] buf  = Encoding.Unicode.GetBytes(StringCompressionUtility.Compress(data));

                if (saveDataPtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(saveDataPtr);
                }
                saveDataPtr = Marshal.AllocHGlobal(buf.Length);
                Marshal.Copy(buf, 0, saveDataPtr, buf.Length);

                *saveBuf = saveDataPtr.ToPointer();
                return(buf.Length);
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(Exception))
                {
                    throw;
                }
                else if (ex.GetType() == typeof(SystemException))
                {
                    throw;
                }
            }
            finally
            {
                InstrumentManager.InstExclusiveLockObject.ExitReadLock();
            }
            return(0);
        }
Exemplo n.º 4
0
        /// <summary>
        /// アプリケーションのメイン エントリ ポイントです。
        /// </summary>
        /// <param name="parentModule">親モジュール</param>
        public static void Main(IntPtr parentModule)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            System.Resources.ResourceManager rm =
                new System.Resources.ResourceManager("System", typeof(UriFormat).Assembly);
            string dummy = rm.GetString("Arg_EmptyOrNullString");

            ThreadPool.SetMaxThreads(250, 1000);

            MameIF.Initialize(parentModule);
            var threadStart = new ManualResetEvent(false);

            mainThread = new Thread(new ThreadStart(() =>
            {
                threadStart.Set();
                Settings.Default.Reload();

                if (string.IsNullOrWhiteSpace(Settings.Default.OutputDir))
                {
                    Settings.Default.OutputDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                }

                f_CurrentSamplingRate = 48000;
                int.TryParse(Settings.Default.SampleRate, out f_CurrentSamplingRate);

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                using (var fs = new FormSplash())
                {
                    fs.Show();
                    if (!IsVSTiMode())
                    {
                        while (fs.Opacity != 1)
                        {
                            fs.Opacity += 0.1;
                            Thread.Sleep(50);
                            fs.Refresh();
                        }
                    }
                    else
                    {
                        formSplash  = fs;
                        fs.Opacity += 1;
                        fs.Refresh();
                    }

                    try
                    {
                        var fm    = new FormMain();
                        fm.Shown += (_, __) =>
                        {
                            if (!IsVSTiMode())
                            {
                                fm.BeginInvoke(new MethodInvoker(() => { fs.Close(); }));
                            }

                            if (!string.IsNullOrEmpty(Settings.Default.EnvironmentSettings))
                            {
                                try
                                {
                                    var dso = StringCompressionUtility.Decompress(Settings.Default.EnvironmentSettings);
                                    InstrumentManager.ClearAllInstruments();
                                    var settings = JsonConvert.DeserializeObject <EnvironmentSettings>(dso, JsonAutoSettings);
                                    InstrumentManager.RestoreSettings(settings);
                                }
                                catch (Exception ex)
                                {
                                    if (ex.GetType() == typeof(Exception))
                                    {
                                        throw;
                                    }
                                    else if (ex.GetType() == typeof(SystemException))
                                    {
                                        throw;
                                    }

                                    MessageBox.Show(ex.ToString());
                                }
                            }
                        };
                        Application.Run(fm);

                        var so = JsonConvert.SerializeObject(SaveEnvironmentSettings(), Formatting.Indented, JsonAutoSettings);
                        Settings.Default.EnvironmentSettings = StringCompressionUtility.Compress(so);
                        Settings.Default.Save();
                    }
                    catch (Exception ex)
                    {
                        if (ex.GetType() == typeof(Exception))
                        {
                            throw;
                        }
                        else if (ex.GetType() == typeof(SystemException))
                        {
                            throw;
                        }

                        MessageBox.Show(ex.ToString());
                    }

                    ShuttingDown?.Invoke(typeof(Program), EventArgs.Empty);
                }
            }))
            {
                Priority = ThreadPriority.BelowNormal
            };
            mainThread.SetApartmentState(ApartmentState.STA);
            mainThread.Start();
            threadStart.WaitOne();
        }