private void BtnFindNearPrime_Click(object sender, EventArgs e) { this.LastExec_IsPrime = false; IntTools.Normalize(this.IsPrimeInputValue); string str = this.IsPrimeInputValue.Text; if (IntTools.IsULongString(str) == false) { MessageBox.Show( "0 ~ " + ulong.MaxValue + " の整数を入力して下さい。", "判定できません", MessageBoxButtons.OK, MessageBoxIcon.Warning ); this.PostExec_IsPrime(); return; } this.NennotameMkPrimeDat(); WorkDir workDir = new WorkDir(); string outFile = workDir.MakePath(); this.ProcMan.Start(Gnd.I.Prime64File, "//MOLP " + StringTools.OUT_PFX + " //O \"" + outFile + "\" " + this.CmdPartOptUMRTM() + "/LH " + str); using (BusyDlg f = new BusyDlg()) { f.SetInterval(delegate { return(this.ProcMan.IsEnd() == false); }); f.ShowDialog(); } string[] lines = File.ReadAllLines(outFile); lines = StringTools.Prime64StdoutFilter(lines); string str_l = lines[0]; string str_h = lines[1]; if (str_l == "0") { str_l = "(なし)"; } if (str_h == "0") { str_h = Gnd.I.PRIME_MIN_OVER_UL; } this.IsPrimeOutput.Text = "入力値:\r\n" + str + "\r\n入力値より小さい最大の素数:\r\n" + str_l + "\r\n入力値より大きい最小の素数:\r\n" + str_h; //this.IsPrimeOutput.Text = "n=\r\n" + str + "\r\nnより小さい最大の素数=\r\n" + str_l + "\r\nnより大きい最小の素数=\r\n" + str_h; //this.IsPrimeOutput.Text = str + "\r\n" + str_l + "\r\n" + str_h + "\r\n\r\n# 上から「入力値, 入力値より小さい最大の素数, 入力値より大きい最小の素数」です。"; //this.IsPrimeOutput.Text = str_l + "\r\n" + str_h + "\r\n\r\n# 上から「 " + str + " より小さい最大の素数」「 " + str + " より大きい最小の素数」です。素数が見つからない場合は 0 を表示します。"; workDir.Destroy(); workDir = null; this.PostExec_IsPrime(); }
private void BtnIsPrime_Click(object sender, EventArgs e) { this.LastExec_IsPrime = true; IntTools.Normalize(this.IsPrimeInputValue); string str = this.IsPrimeInputValue.Text; if (IntTools.IsULongString(str) == false) { MessageBox.Show( "0 ~ " + ulong.MaxValue + " の整数を入力して下さい。", "判定できません", MessageBoxButtons.OK, MessageBoxIcon.Warning ); this.PostExec_IsPrime(); return; } this.NennotameMkPrimeDat(); WorkDir workDir = new WorkDir(); string outFile = workDir.MakePath(); this.ProcMan.Start(Gnd.I.Prime64File, "//MOLP " + StringTools.OUT_PFX + " //O \"" + outFile + "\" " + this.CmdPartOptUMRTM() + "/P " + str); using (BusyDlg f = new BusyDlg()) { f.SetInterval(delegate { return(this.ProcMan.IsEnd() == false); }); f.ShowDialog(); } string[] lines = File.ReadAllLines(outFile); lines = StringTools.Prime64StdoutFilter(lines); string ans = lines[0]; if (ans == "IS_PRIME") { this.IsPrimeOutput.Text = str + "\r\nこの値は 素数 です。"; } else if (ans == "IS_NOT_PRIME") { this.IsPrimeOutput.Text = str + "\r\nこの値は 素数 ではありません。2未満の整数又は合成数です。"; } else { this.IsPrimeOutput.Text = str + "\r\n(エラー)"; } workDir.Destroy(); workDir = null; this.PostExec_IsPrime(); }
private void BtnFactorize_Click(object sender, EventArgs e) { IntTools.Normalize(this.FactorizeInputValue); string str = this.FactorizeInputValue.Text; if (IntTools.IsULongString(str) == false || ulong.Parse(str) < 1) { MessageBox.Show( "1 ~ " + ulong.MaxValue + " の整数を入力して下さい。", "素因数分解できません", MessageBoxButtons.OK, MessageBoxIcon.Warning ); this.PostExec_Factorize(); return; } this.NennotameMkPrimeDat(); WorkDir workDir = new WorkDir(); string outFile = workDir.MakePath(); this.ProcMan.Start(Gnd.I.Prime64File, "//MOLP " + StringTools.OUT_PFX + " //O \"" + outFile + "\" " + this.CmdPartOptUMRTM() + "/F " + str); using (BusyDlg f = new BusyDlg()) { f.SetInterval(delegate { return(this.ProcMan.IsEnd() == false); }); f.ShowDialog(); } string[] lines = File.ReadAllLines(outFile); lines = StringTools.Prime64StdoutFilter(lines); if (this.CheckFactorizeBekijou.Checked) { lines = this.ToBekijou(lines); } if (this.Chk改行しない.Checked) { this.FactorizeOutput.Text = str + " = " + string.Join(" * ", lines); } else { this.FactorizeOutput.Text = str + " の 素因数 は ...\r\n" + string.Join("\r\n", lines); } workDir.Destroy(); workDir = null; this.PostExec_Factorize(); }
private void MainWin_FormClosed(object sender, FormClosedEventArgs e) { if (Gnd.I.SettingData.KeepPrimeDat == false) { // Prime64.exe の終了待ち。 { Process p; { ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = Gnd.I.Prime64File; psi.Arguments = "/P 1"; psi.CreateNoWindow = true; psi.UseShellExecute = false; p = Process.Start(psi); } using (BusyDlg f = new BusyDlg()) { f.SetInterval(delegate { return(p.HasExited == false); }); f.SetMessage("プログラムを終了しています..."); f.ShowDialog(); } } using (Mutex m = new Mutex(false, Gnd.I.FACTORY_COMMON_MUTEX)) using (new IMutex(m)) { File.Delete("Prime.dat"); } } }
private void MainWin_Load(object sender, EventArgs e) { this.MinimumSize = this.Size; { bool existsPrimeDat; using (Mutex m = new Mutex(false, Gnd.I.FACTORY_COMMON_MUTEX)) using (new IMutex(m)) { existsPrimeDat = File.Exists("Prime.dat"); } if (existsPrimeDat == false) { // Prime.dat のため、ディスクの空きチェック { DriveInfo di = new DriveInfo(BootTools.SelfDir.Substring(0, 2)); int diskFree_mb = IntTools.ToInt(di.AvailableFreeSpace / 1000000.0); if (diskFree_mb < Gnd.I.SettingData.DiskFreeOnBoot_MB) // ? < 300 MB { string message = "起動に必要なディスクの空き領域が不足しています。(" + diskFree_mb + "_" + Gnd.I.SettingData.DiskFreeOnBoot_MB + ")"; MessageBox.Show(message, Program.APP_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); throw new Exception(message); } } #if true { ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = Gnd.I.Prime64File; psi.Arguments = "/P 1"; psi.CreateNoWindow = true; psi.UseShellExecute = false; Process.Start(psi); // 待たない! } #else // old @ 2017.5.17 this.ProcMan.Start(Gnd.I.Prime64File, "/P 1"); using (BusyDlg f = new BusyDlg()) { f.SetInterval(delegate { return(this.ProcMan.IsEnd() == false); }); f.SetMessage("データファイルを作成しています..."); f.ShowDialog(); this.Location = f.Location; } if (Gnd.I.SettingData.HidePrimeDat) { this.ProcMan.Start("ATTRIB.EXE", "+S +H Prime.dat"); this.ProcMan.End(); } #endif } } }