/// <summary> /// 建立更新控制端 /// </summary> /// <param name="code"></param> private void builtUpdateControler(BaseCommunication sender, Code code) { BaseControler controler = sender as BaseControler; if (controler != null) { PortCode readyCode = code as PortCode; if (readyCode != null) { if (serverupdateControler == null) { serverupdateControler = new FileControler(controler.ServerAddress, readyCode.Port); } if (serverupdateControler != null) { serverupdateControler.CloseConnections(); Thread.Sleep(500); serverupdateControler = new FileControler(controler.ServerAddress, readyCode.Port); serverupdateControler.SourceFile = updatedFile; serverupdateControler.DestinationFile = ICanSeeYou.Common.IO.GetName(updatedFile); serverupdateControler.IsDownload = false;//上传更新文件 serverupdateControler.Open(); } } } }
public static T GetContent <T>(PathType contentType, string contentFileName) where T : class { string path = Path.Combine(GetPath(contentType), contentFileName); object retT = null; Type tType = typeof(T); if (tType == typeof(Image)) { retT = Bitmap.FromFile(path); } else if (tType == typeof(System.Media.SoundPlayer)) { retT = new System.Media.SoundPlayer(path); } else if (tType == typeof(MapResponse)) { retT = FileControler.Open(path); } else { retT = System.IO.File.OpenRead(path); } return(retT as T); }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { bool save = true; if (this.IsNew) { using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.Filter = FileControler.FILTER; if (sfd.ShowDialog() == DialogResult.OK) { this.MapPath = sfd.FileName; } else { save = false; } } } if (save) { try { FileControler.Save(this.MapPath, this.pcmMapPaint.Cells, this.GetBricks(), this.pcmMapPaint.TileWidth, this.pcmMapPaint.TileHeigth); this.IsNew = false; MessageBox.Show("Os mapa foi salvo com sucesso."); } catch (Exception ex) { MessageBox.Show("Não foi possível salvar o mapa com sucesso. Tente novamente.\r\nDetalhes: " + ex.Message); } } }
public ClipSharing(string panelName) : base(nameof(ClipSharing), panelName) { Directory.CreateDirectory(TemporaryPath); // clear folder and children files FileControler.ClearDataDirectory(TemporaryPath); //LastLoadTime = DateTime.Now; AccessRetryCount = 10; }
private void MakeBackUpFile(string[] filePath, string backupDirectory) { // make folder Directory.CreateDirectory(backupDirectory); // copy files foreach (var file in filePath) { FileControler.CopyAndReplace(file, backupDirectory); } }
private void btnAddBrick_Click(object sender, EventArgs e) { if (ofdMapEdit.ShowDialog() == DialogResult.OK) { foreach (string fileName in ofdMapEdit.FileNames) { Brick brk = new Brick(); brk.ImagePath = fileName; brk.Image = Bitmap.FromFile(brk.ImagePath); BrickListItem item = new BrickListItem(); item.Brick = brk; item.Text = FileControler.GetFileName(brk.ImagePath); this.ltvBricks.Items.Add(item); } } }
/// <summary> /// 建立文件控制端 /// </summary> /// <param name="code"></param> private void builtFileControler(BaseCommunication sender, Code code) { BaseControler controler = sender as BaseControler; if (controler != null) { PortCode readyCode = code as PortCode; if (readyCode != null) { if (fileControler != null) { fileControler.CloseConnections(); } fileControler = new FileControler(controler.ServerAddress, readyCode.Port); fileControler.Refrush = new RefrushEvent(UpdateExplorerView); } } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = FileControler.FILTER; if (ofd.ShowDialog() == DialogResult.OK && System.IO.File.Exists(ofd.FileName)) { this.IsNew = false; this.MapPath = ofd.FileName; this.BrickPath = FileControler.GetPath(ofd.FileName) + "Bricks\\"; MapResponse response = FileControler.Open(ofd.FileName); this.pcmMapPaint.TileHeigth = response.TileHeight; this.pcmMapPaint.TileWidth = response.TileWidth; this.pcmMapPaint.QtdColumns = response.Matrix.Columns; this.pcmMapPaint.QtdRows = response.Matrix.Rows; this.pcmMapPaint.Cells = response.Matrix; this.ltvBricks.Items.Clear(); for (int i = 0; i < response.Bricks.Count; i++) { Brick brk = response.Bricks[i]; brk.IsNew = false; brk.Image = Bitmap.FromFile(this.BrickPath + brk.ImagePath); BrickListItem item = new BrickListItem(); item.Brick = brk; item.Text = brk.ImagePath; this.ltvBricks.Items.Add(item); } this.pcmMapPaint.Invalidate(); dudWidth.Text = this.pcmMapPaint.TileHeigth.ToString(); dudHeigth.Text = this.pcmMapPaint.TileWidth.ToString(); nudColumns.Value = this.pcmMapPaint.QtdColumns; nudRows.Value = this.pcmMapPaint.QtdRows; this.lblSize.Text = pcmMapPaint.Width.ToString() + "x" + pcmMapPaint.Height.ToString(); } }
public void SaveClipBoard(object sender, EventArgs e) { var dataObj = Clipboard.GetDataObject(); if (dataObj == null || dataObj.GetFormats().Length <= 0) { return; } // 現在Save中の場合は強制実行するか確認する var inputFileList = Directory.EnumerateFileSystemEntries(TemporaryPath).ToArray(); if (inputFileList.Any(f => Path.GetFileName(f) == "START") && !inputFileList.Any(f => Path.GetFileName(f) == "END")) { var dialogResult = MessageBox.Show("コピー中のファイルが存在します。\r\n強制的にセーブしますか?" , "強制セーブ確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.No) { return; } } // clear folder amd children files FileControler.ClearDataDirectory(TemporaryPath); File.Create(Path.Combine(TemporaryPath, "START")).Close(); string[] formats = dataObj.GetFormats(); for (int fNo = 0; fNo < formats.Length; fNo++) { string dataFormat = formats[fNo]; string outputFilePath = Path.Combine(TemporaryPath, $"{dataFormat}"); var clipData = dataObj.GetData(dataFormat); if (clipData == null) { continue; } // Formatに合わせて保存 switch (clipData.GetType().Name) { case DATATYPE_BMP: var img = Clipboard.GetImage(); img.Save($"{outputFilePath}.{DATATYPE_BMP}"); break; case DATATYPE_BIN: var ms = (MemoryStream)dataObj.GetData(dataFormat); File.WriteAllBytes($"{outputFilePath}.{DATATYPE_BIN}", ms.ToArray()); break; case "String[]": string[] outputData = (string[])dataObj.GetData(dataFormat); if (dataFormat == "FileDrop") { Directory.CreateDirectory(outputFilePath); for (int i = 0; i < outputData.Length; i++) { FileControler.CopyAndReplace(outputData[i], outputFilePath); //outputData[i] = Path.Combine(outputFilePath, Path.GetFileName(outputData[i])); } } using (var sw = new StreamWriter($"{outputFilePath}.{DATATYPE_STR_ARRAY}")) { sw.Write(String.Join("\r\n", outputData)); } break; case DATATYPE_TEXT: using (var sw = new StreamWriter($"{outputFilePath}.{DATATYPE_TEXT}")) { sw.Write(dataObj.GetData(dataFormat)); } break; default: #warning 想定外のフォーマット:ログ出力処理 Debug.WriteLine($"{fNo}__{dataFormat}__{clipData.GetType().Name}"); break; } } File.Create(Path.Combine(TemporaryPath, "END")).Close(); ShareCompornent.NotifyControl.ShowBalloonTip(3000, "ClipBord共有", "ClipBordセーブ完了", ToolTipIcon.Info); inputFileList = Directory.EnumerateFileSystemEntries(TemporaryPath).ToArray(); LastLoadTime = Directory.EnumerateFiles(TemporaryPath).Max(f => File.GetLastWriteTime(f)); }