public void ArchiveRecords(int matchNum) { string subPath = SavePath + (SavePath.EndsWith("\\") ? "" : "\\") + matchNum.ToString() + "\\"; Directory.CreateDirectory(subPath); List <string> files = Directory.EnumerateFiles(SavePath, "*" + ScoutingJson.MatchRecordExtension, SearchOption.TopDirectoryOnly).ToList(); foreach (string file in files) { try { File.Move(file, subPath + Util.GetFileName(file, true)); } catch (Exception e) { string msg = "Could not move file " + Util.GetFileName(file, true); Util.DebugLog(LogLevel.Error, msg); MessageBox.Show(msg + "\n\n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); ProcessAllNewFolders = false; return; } } }
private void OpenToolStripMenuItem_Click(object sender, EventArgs e) { try { if (MainPanel.PalSource != null) { switch (MyMessageBox.Show(Language.DICT["MainTitle"], Language.DICT["MsgInfoHintForSave"], MyMessageBoxButtons.YesNoCancel)) { case DialogResult.Yes: SaveToolStripMenuItem_Click(null, new EventArgs()); break; case DialogResult.No: break; default: return; } } OpenFileDialog openFileDialog = new OpenFileDialog { Filter = "Palette File|*.pal|All Files|*.*", InitialDirectory = Application.StartupPath, Title = Language.DICT["MainTitle"], DefaultExt = "pal", CheckPathExists = true }; if (openFileDialog.ShowDialog() == DialogResult.OK) { if (SavePath.EndsWith(".ini")) { //TODO } else { SavePath = openFileDialog.FileName; IsSaved = true; Undos.Clear(); Redos.Clear(); MainPanel.Selections.Clear(); MainPanel.PalSource = new PalFile(SavePath); MainPanel.Refresh(); MainPanel_SelectedIndexChanged(null, new EventArgs()); MainPanel_BackColorChanged(null, new EventArgs()); UpdateTitle(Language.DICT["MainTitleEmptyName"]); CurrentStatusLabel.Text = Language.DICT["StslblOpenSucceed"]; } } } catch (Exception ex) { SavePath = ""; IsSaved = false; MainPanel.Close(); CurrentStatusLabel.Text = Language.DICT["StslblOpenFailed"]; UpdateTitle(Language.DICT["MainTitleEmptyName"]); MyMessageBox.Show(Language.DICT["MainTitle"], Language.DICT["MsgFatalOpen"] + ex.Message); } }
/// <summary> /// 储存文件并返回结果 /// </summary> /// <returns>Bool</returns> public bool Save() { if (!Directory.Exists(sv.MapPath(SavePath))) { Directory.CreateDirectory(sv.MapPath(SavePath)); } if (ReqFile == null) { Err = 4; return(false); } if (ReqFile.ContentLength > MaxSize) { Err = 1; return(false); } var fil = Filter.Where(m => m == Path.GetExtension(ReqFile.FileName.ToLower())); string TempFilePath = TempFolder.EndsWith("/") ? TempFolder + NewFileName : TempFolder + "/" + NewFileName; string NewFilepath = SavePath.EndsWith("/") ? SavePath + NewFileName : SavePath + "/" + NewFileName; if (fil.Count() != 1) { Err = 2; return(false); } if (SafePicture) { try { var rawimg = Image.FromStream(ReqFile.InputStream); rawimg.Dispose(); } catch (Exception) { Err = 2; return(false); } } try { ReqFile.SaveAs(sv.MapPath(TempFilePath)); } catch (Exception) { Err = 3; return(false); } if (Resize) { IASPJpeg j = new ASPJpeg(); j.Open(sv.MapPath(TempFilePath)); j.Quality = 80; int ow = j.OriginalWidth; int oh = j.OriginalHeight; if (ow > MaxWidth) { j.Width = MaxWidth; if (Constrain) { j.Height = (int)((MaxWidth.CDbl() / ow.CDbl()) * oh.CDbl()); if (Crop && j.Height > MaxHeight) { j.Crop(0, (j.Height - MaxHeight) / 2, j.Width, MaxHeight + (j.Height - MaxHeight) / 2); } } else { j.Height = MaxHeight; } } j.Save(sv.MapPath(NewFilepath)); StoredPath = NewFilepath; File.Delete(sv.MapPath(TempFilePath)); return(true); } else { File.Move(sv.MapPath(TempFilePath), sv.MapPath(NewFilepath)); StoredPath = NewFilepath; return(true); } }