private void ensureBtn_Click(object sender, EventArgs e)
        {
            string MainVersion   = MainVersiontxt.Text;
            string MaxSubVersion = MaxSubVersiontxt.Text;
            List <configurationFilePath> FilePaths = new List <configurationFilePath>();

            foreach (DataGridViewRow item in localtionSetting.Rows)
            {
                if (item.Cells[0].Value != null && item.Cells[1].Value != null)
                {
                    FilePaths.Add(new configurationFilePath {
                        Name = item.Cells[0].Value.ToString(),
                        Path = item.Cells[1].Value.ToString()
                    });
                }
            }
            //更新到config文件
            configuration config = new configuration {
                MaxSubVersion = MaxSubVersion,
                CurrVersion   = currentlabel.Text,
                MinSubVersion = MinSubVersiontxt.Text,
                MainVersion   = MainVersion,
                VersionCount  = nowsublabel.Text,
                FilePaths     = FilePaths
            };

            string       xml = EventXml.Serializer(typeof(configuration), config);
            StreamWriter sw  = new StreamWriter("Publish.config"); //这里写上你要保存的路径

            sw.WriteLine(xml);                                     //按行写
            sw.Close();                                            //关闭
            this.DialogResult = DialogResult.OK;
        }
Beispiel #2
0
        private void PublishBtn_Click(object sender, EventArgs e)
        {
            if (this.bdCountLbl.Text == "0")
            {
                MessageBox.Show("发布目录UpdateFiles下没有任何文件,不允许发布!");
                return;
            }
            configuration config = EventXml.Deserialize(typeof(configuration), LinqToXml.GetStringByXml("Publish.config")) as configuration;
            var           maxsub = config.MaxSubVersion;
            var           mainbb = config.MainVersion;
            var           minsub = config.MinSubVersion;
            var           nowsub = config.CurrVersion;
            var           count  = config.VersionCount;
            string        nowbb;

            if (int.Parse(nowsub) == int.Parse(maxsub))
            {
                //主版本加一,当前值为最小值
                config.CurrVersion = minsub;
                config.MainVersion = (int.Parse(mainbb) + 1).ToString();
                nowbb = config.MainVersion + "." + config.CurrVersion;
                config.VersionCount = (int.Parse(count) + 1).ToString();
                string       xml = EventXml.Serializer(typeof(configuration), config);
                StreamWriter sw  = new StreamWriter("Publish.config"); //这里写上你要保存的路径
                sw.WriteLine(xml);                                     //按行写
                sw.Close();                                            //关闭
            }
            else
            {
                //主版本不动,当前值加一
                config.CurrVersion = (int.Parse(nowsub) + 1).ToString();
                nowbb = config.MainVersion + "." + config.CurrVersion;
                config.VersionCount = (int.Parse(count) + 1).ToString();
                string       xml = EventXml.Serializer(typeof(configuration), config);
                StreamWriter sw  = new StreamWriter("Publish.config"); //这里写上你要保存的路径
                sw.WriteLine(xml);                                     //按行写
                sw.Close();                                            //关闭
            }
            foreach (var item in paths)
            {
                MoveFile.CopyDir("UpdateFiles", item, config.MainVersion, config.CurrVersion);
            }
            //备份完成
            MoveFile.BakLog("UpdateFiles", "UpdateHistory", nowbb);
            //修改版本号,取最大值,最小值,现在的值  修改现在的值 修改发布版本次数


            MessageBox.Show($"发布成功,当前补丁版本为:{nowbb}");
            MainForm_Load(sender, e);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Trace.Listeners.Add(new TextWriterTraceListener(errorFileName));
            Trace.AutoFlush = true;

            if (args.Any(c => c.ToLower() == "/armobs"))
            {
                if (args.Length == 1)
                {
                    var obs32List = Process.GetProcessesByName("obs32");
                    var obs64List = Process.GetProcessesByName("obs64");
                    if (obs32List.Length == 0 && obs64List.Length == 0)
                    {
                        //No OBS found. Cancel operation.
                        File.Delete(OBSUtils.obswszip);

                        return;
                    }
                    List <Process> obsProcesses = new List <Process>();
                    obsProcesses.AddRange(obs32List);
                    obsProcesses.AddRange(obs64List);

                    if (obsProcesses.Count != 1)
                    {
                        //Multiple OBS instances found. Cancel operation.
                        File.Delete(OBSUtils.obswszip);

                        return;
                    }
                    var obsProcess = obsProcesses.First();

                    string path = OBSUtils.GetProcessPath(obsProcess.Id);


                    string zipTempPath = Path.GetFileNameWithoutExtension(OBSUtils.obswszip);

                    OBSUtils.ExtractZip(OBSUtils.obswszip, zipTempPath);


                    OBSUtils.DirectoryCopy(zipTempPath, OBSUtils.GetPathFromOBSExecutable(path), true);

                    File.Delete(OBSUtils.obswszip);
                    Directory.Delete(zipTempPath, true);

                    var obsGlobalFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "obs-studio", "global.ini");

                    if (File.Exists(obsGlobalFilePath) && !File.ReadAllText(obsGlobalFilePath).Contains("[WebsocketAPI]"))
                    {
                        Trace.WriteLine("File exist and not contain web socket.");
                        while (!obsProcess.HasExited)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine(Texts.rm.GetString("OBSINTEGRATIONINSTALL", Texts.cultereinfo));
                            sb.AppendLine("");
                            sb.AppendLine(Texts.rm.GetString("OBSINTEGRATIONAPPLY", Texts.cultereinfo));
                            MessageBox.Show(sb.ToString());
                        }

                        using (StreamWriter outputFile = new StreamWriter(obsGlobalFilePath))
                        {
                            outputFile.WriteLine("");
                            outputFile.WriteLine("[WebsocketAPI]");
                            outputFile.WriteLine("ServerPort=4444");
                            outputFile.WriteLine("DebugEnabled=false");
                            outputFile.WriteLine("AlertsEnabled=false");
                            outputFile.WriteLine("AuthRequired=false");
                        }

                        bool shouldRepeat = true;
                        while (shouldRepeat)
                        {
                            var obs32List2 = Process.GetProcessesByName("obs32");
                            var obs64List2 = Process.GetProcessesByName("obs64");

                            shouldRepeat = obs32List2.Length == 0 && obs64List2.Length == 0;
                            if (!shouldRepeat)
                            {
                                break;
                            }

                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine(Texts.rm.GetString("OBSINTEGRATIONINSTALLSUCESSFULL", Texts.cultereinfo));
                            sb.AppendLine("");
                            sb.AppendLine(Texts.rm.GetString("OBSINTEGRATIONCONFIRMOBS", Texts.cultereinfo));
                            MessageBox.Show(sb.ToString());
                        }
                    }

                    return;
                }
            }

#if FORCE_SILENCE
            Silent = true;
#else
            Silent = args.Any(c => c.ToLower() == "/s");
#endif
            const string appName = "DisplayButtons";
            bool         createdNew;

            mutex = new Mutex(true, appName, out createdNew);

            if (!createdNew)
            {
                //app is already running! Exiting the application
                if (MessageBox.Show(Texts.rm.GetString("ALREADYDISPLAYBUTTONISOPEN", Texts.cultereinfo), Texts.rm.GetString("ALREADYDISPLAYBUTTONISOPENTITLE", Texts.cultereinfo), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    var myapp = Process.GetProcessesByName(Assembly.GetCallingAssembly().GetName().Name);

                    List <Process> obsProcesses = new List <Process>();
                    obsProcesses.AddRange(myapp);


                    if (obsProcesses.Count > 1)
                    {
                        var last = obsProcesses.First();
                        last.Kill();
                    }
                }
                //return;
            }


            Application.ThreadException += Application_ThreadException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;


            EventXml.LoadSettings();

            ApplicationSettingsManager.LoadSettings();
            Texts.initilizeLang();
            errorText = String.Format(Texts.rm.GetString("INTEGRATIONERROROCURRED", Texts.cultereinfo), errorFileName);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            OBSUtils.PrepareOBSIntegration();
            if (ApplicationSettingsManager.Settings.FirstRun)
            {
                FirstSetupForm firstRunForm = new FirstSetupForm();
                Application.Run(firstRunForm);
                if (!firstRunForm.FinishedSetup)
                {
                    return;
                }
            }
            //  EnsureBrowserEmulationEnabled("DisplayButtons.exe");

            new WebBrowserInstanceHelper().SetBrowserFeatureControl();

            dynamic form = Activator.CreateInstance(FindType("DisplayButtons.Forms.ActionHelperForms.MainFormMenuOption")) as Form;

            if (form.ShowDialog() == DialogResult.OK)
            {
                Initilizator.mode         = 0;
                Initilizator.ServerThread = new ServerThread();
                Initilizator.ServerThread.Start();


                Debug.WriteLine("MODO SOCKET CLIENT");
            }
            else
            {
                // Silent = true;
                Debug.WriteLine("MODO USB");
                Initilizator.mode = 1;

                Adbserver = new AdbServer();

                Adbserver.StartServer(Path.Combine(Application.StartupPath, @"Data\adb\adb.exe"), restartServerIfNewer: true);

                monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)));
                client  = new AdbClient(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort), Factories.AdbSocketFactory);

                monitor.DeviceConnected    += MainForm.DeviceAdbConnected;
                monitor.DeviceDisconnected += MainForm.DeviceAdbDisconnected;
                monitor.Start();



                if (client.GetDevices().Count == 1)
                {
                    Debug.WriteLine("ONE DEVICE");



                    //   client.ExecuteRemoteCommand("am start -a android.intent.action.VIEW -e mode 1 net.nickac.DisplayButtons/.MainActivity", client.GetDevices().First(), null);

                    DevicePersistManager.PersistUsbMode(client.GetDevices().First());
                    //      client.CreateForward(client.GetDevices().First(), "tcp:5095", "tcp:5095", true);

                    Initilizator.ClientThread = new ClientThread();
                    Initilizator.ClientThread.Start();
                }
                else
                {
                    Initilizator.ClientThread = new ClientThread();
                }
            }
            Application.Run(new MainForm());


            //Application.Run(new MainFormMenuOption());
            OBSUtils.Disconnect();
            if (Initilizator.mode == 1)
            {
                foreach (var device in client.GetDevices().ToList())
                {
                    //   client.ExecuteRemoteCommand("am force-stop net.nickac.DisplayButtons", device, null);
                    // client.ExecuteRemoteCommand("kill-server", device, null);

                    //   client.KillAdb();
                }
            }

            //   client.KillAdb();
            EventXml.SaveSettings();
            ApplicationSettingsManager.SaveSettings();
            DevicePersistManager.SaveDevices();

            NetworkChange.NetworkAddressChanged      -= NetworkChange_NetworkAddressChanged;
            NetworkChange.NetworkAvailabilityChanged -= NetworkChange_NetworkAddressChanged;
            Trace.Flush();
        }
Beispiel #4
0
        public static void CopyDir(string srcPath, string aimPath, string mainversion, string subversion)
        {
            try
            {
                string oldAimpath = aimPath;
                aimPath += "\\UpdateFiles";
                // 检查目标目录是否以目录分割字符结束如果不是则添加
                if (aimPath[aimPath.Length - 1] != System.IO.Path.DirectorySeparatorChar)
                {
                    aimPath += System.IO.Path.DirectorySeparatorChar;
                }
                //// 判断目标目录是否存在如果不存在则新建,
                //if (!System.IO.Directory.Exists(aimPath))
                //{
                //    System.IO.Directory.CreateDirectory(aimPath);
                //}
                // 得到源目录的文件列表,该里面是包含文件以及目录路径的一个数组
                // 如果你指向copy目标文件下面的文件而不包含目录请使用下面的方法
                // string[] fileList = Directory.GetFiles(srcPath);
                //将当前目录下的server.xml改信息

                string[] fileList = System.IO.Directory.GetFileSystemEntries(srcPath);
                if (fileList != null && fileList.Length != 0)
                {
                    ServerSetting serverSetting = EventXml.Deserialize(typeof(ServerSetting), LinqToXml.GetStringByXml(oldAimpath + "\\bin\\server.xml")) as ServerSetting;

                    // 遍历所有的文件和目录
                    foreach (string file in fileList)
                    {
                        FileInfo fileInfo = new FileInfo(file);
                        var      size     = fileInfo.Length.ToString();
                        var      name     = file.Split('\\')[1];
                        if (!serverSetting.UpdateFile.Where(s => name == s.SaveFileName).Any())
                        {
                            serverSetting.UpdateFile.Add(new ServerSettingUpdateFile {
                                SaveFileName  = name,
                                FileSize      = size,
                                NeedReStart   = "False",
                                ChildVersion  = subversion,
                                CopyType      = "0",
                                FilePath      = name,
                                GUID          = Guid.NewGuid().ToString("N"),
                                IsRollBack    = "False",
                                IsZipFile     = "False",
                                MainVersion   = mainversion,
                                NeedReg       = "False",
                                RuleType      = "1",
                                Title         = "批量发布:" + name,
                                SavePath      = "",
                                StartServices = "",
                                StopServices  = "",
                                Memo          = "",
                                NeedVersion   = "",
                                NewVersion    = ""
                            });
                        }
                        else
                        {
                            serverSetting.UpdateFile.ForEach(i =>
                            {
                                if (name == i.SaveFileName)
                                {
                                    i.MainVersion  = mainversion;
                                    i.ChildVersion = subversion;
                                    i.FileSize     = size;
                                }
                            });
                        }

                        File.Copy(file, aimPath + System.IO.Path.GetFileName(file), true);
                    }
                    string       xmlsss = EventXml.Serializer(typeof(ServerSetting), serverSetting);
                    string       xml    = xmlsss.Replace("xsi:type=\"xsd:string\"", "");
                    StreamWriter sw     = new StreamWriter(oldAimpath + "\\bin\\server.xml"); //这里写上你要保存的路径
                    sw.WriteLine(xml);                                                        //按行写
                    sw.Close();                                                               //关闭
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }