Пример #1
0
        public static string CheckLogFile(string FileName)
        {
            if (Program.WindowsStoreApp)
            {
                CustomMessageBox.Show(Strings.Not_available_when_used_as_a_windows_store_app);
                return("");
            }

            var dir = Settings.GetDataDirectory() + "LogAnalyzer" +
                      Path.DirectorySeparatorChar;

            var runner = dir + "runner.exe";

            var zip = dir + "LogAnalyzer.zip";

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            //if (!File.Exists(runner))
            {
                Loading.ShowLoading("Downloading LogAnalyzer");
                bool gotit = false;
                if (Environment.Is64BitOperatingSystem)
                {
                    gotit = Download.getFilefromNet(
                        "https://firmware.ardupilot.org/Tools/MissionPlanner/LogAnalyzer/LogAnalyzer64.zip",
                        zip);
                }
                else
                {
                    gotit = Download.getFilefromNet(
                        "https://firmware.ardupilot.org/Tools/MissionPlanner/LogAnalyzer/LogAnalyzer.zip",
                        zip);
                }

                // download zip
                if (gotit)
                {
                    Loading.ShowLoading("Extracting zip file");
                    // extract zip
                    FastZip fzip = new FastZip();
                    fzip.ExtractZip(zip, dir, "");
                }
                else
                {
                    if (!File.Exists(runner))
                    {
                        CustomMessageBox.Show("Failed to download LogAnalyzer");
                        return("");
                    }
                }
            }

            if (!File.Exists(runner))
            {
                CustomMessageBox.Show("Failed to download LogAnalyzer");
                return("");
            }

            var sb = new StringBuilder();

            Process P = new Process();

            P.StartInfo.FileName  = runner;
            P.StartInfo.Arguments = @" -x """ + FileName + @".xml"" -s """ + FileName + @"""";

            P.StartInfo.UseShellExecute  = false;
            P.StartInfo.WorkingDirectory = dir;

            P.StartInfo.RedirectStandardOutput = true;
            P.StartInfo.RedirectStandardError  = true;

            P.OutputDataReceived += (sender, args) => sb.AppendLine(args.Data);
            P.ErrorDataReceived  += (sender, args) => sb.AppendLine(args.Data);

            try
            {
                Loading.ShowLoading("Running LogAnalyzer");

                P.Start();

                P.BeginOutputReadLine();
                P.BeginErrorReadLine();

                // until we are done
                P.WaitForExit();

                log.Info(sb.ToString());
            }
            catch
            {
                CustomMessageBox.Show("Failed to start LogAnalyzer");
            }

            Loading.Close();

            return(FileName + ".xml");
        }