private void OpenFile() { OpenDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory; OpenDialog.Filter = "Bin File|*.bin"; if (OpenDialog.ShowDialog() == true) { string filepath = OpenDialog.FileName; if (File.Exists(filepath)) { int filelen = (int)IOBinaryOperation.fileLength(filepath); byte[] TempFileData = IOBinaryOperation.readBinaryFile(filepath, filelen); int SegementsCount = filelen / FinalConst.MaxLength + 1; FileData = new byte[SegementsCount, FinalConst.MaxLength]; int Count = 0; for (int i = 0; i < SegementsCount; i++) { for (int j = 0; j < FinalConst.MaxLength; j++) { if (Count < TempFileData.Length) { FileData[i, j] = TempFileData[Count++]; } else { break; } } } Data.ProgressBarMax = SegementsCount; Data.ProgressBarValue = 0; Data.FileInfo += filepath; Data.FileInfo += "\n"; } } }
private void loadBtn_Click(object sender, RoutedEventArgs e) { if (itemRadio_0.IsChecked.HasValue && itemRadio_0.IsChecked.Value) //load from device { int selNum = pLstBox.SelectedIndex + 1; bool isEmpty = CMatrixData.matrixData.determinePresetEmptyInPos(selNum); if (isEmpty) { System.Windows.Forms.MessageBox.Show("You cannot load a empty Preset!"); return; } if (selNum >= 1) { if (NetCilent.netCilent.isConnected()) { _parentWin.isDefaultSetting_beging = true; _parentWin.ackTimer.Stop(); sprocketSaveLoad.IsIndeterminate = true; _parentWin.onLineCheckCounter = 0; CMatrixData.matrixData.sendCMD_recallSinglePreset(selNum); } } } else //load from local { openDlg.InitialDirectory = System.AppDomain.CurrentDomain.BaseDirectory; openDlg.Filter = CDefine.MPFFilter; openDlg.CheckFileExists = true; if (openDlg.ShowDialog() == true) { string strp = openDlg.FileName; int fileLen = (int)IOBinaryOperation.fileLength(strp); if (fileLen == (CDefine.LEN_Sence - 18)) { byte[] iread = IOBinaryOperation.readBinaryFile(strp, fileLen); //sencenlen- CMatrixData.matrixData.iRead_CurrentScene(iread, true); // string bStr = BitConverter.ToString(iread); // Debug.WriteLine("load factory presets: " + bStr); if (NetCilent.netCilent.isConnected()) { _parentWin.isDefaultSetting_beging = true; sprocketSaveLoad.IsIndeterminate = true; _parentWin.onLineCheckCounter = 0; CMatrixData.matrixData.sendCMD_loadFromPC(iread); } } else { System.Windows.MessageBox.Show("Dismatch the factory presets,maybe the file has been damaged!"); return; } } } }
private void exportPresetDataToFile(List <byte> temp) { SaveDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory; SaveDialog.Filter = string.Format("PresetExportFile(*.{0})|*.{0}", FinalConst.PresetFilter); SaveDialog.DefaultExt = string.Format(".{0}", FinalConst.PresetFilter); SaveDialog.AddExtension = true; if (SaveDialog.ShowDialog() == true) { string FilePath = SaveDialog.FileName; IOBinaryOperation.writeBinaryToFile(FilePath, System.Text.Encoding.ASCII.GetBytes(FinalConst.PresetHeader)); IOBinaryOperation.writeBinaryToFile(FilePath, temp.ToArray()); } }
private void saveBtn_Click(object sender, RoutedEventArgs e) { if (itemRadio_0.IsChecked.HasValue && itemRadio_0.IsChecked.Value) //save to device with name { if (pLstBox.SelectedIndex >= 0) { var cnew = new CNewDeveName(); cnew.onsubmitNewDeviceChangedEvent += new CNewDeveName.submitNewDeviceChanged(onsubmitNewDevname); cnew.Tag = "presetChangeName"; cnew.Title = "Change Preset Name"; cnew.setSubTitle("Please input presetname:"); cnew.ShowDialog(); } else { edCpyPreStatus.Text = "You should select a position first."; } } else //save current sence to local PC { saveDlg.InitialDirectory = System.AppDomain.CurrentDomain.BaseDirectory; saveDlg.Filter = "MatrixPresets File|*.MCSP";//matrix Current Scene presetfile saveDlg.OverwritePrompt = true; if (saveDlg.ShowDialog() == true) { string strp = saveDlg.FileName; string fileName = System.IO.Path.GetFileNameWithoutExtension(strp); // MessageBox.Show(fileName); CMatrixData.matrixData.setPresetName(0, fileName); _parentWin.onLineCheckCounter = 0; CMatrixData.matrixData.resetCommunicateStatus(); byte[] mPData = CMatrixData.matrixData.getPackageOfCurrentScene(); bool resload = (IOBinaryOperation.writeBinaryToFile(strp, mPData)); edCpyPreStatus.Text = (resload ? "Sucessful saved to file!" : "Fail to save to file!"); // BitConverter.ToString(mFactoryData);//for show... } } }
private bool ReadSinglePresetFromFile() { bool Result = false; OpenDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory; OpenDialog.Filter = string.Format("PresetExportFile({0})|*.{0}", FinalConst.PresetFilter); if (OpenDialog.ShowDialog() == true) { string filepath = OpenDialog.FileName; if (File.Exists(filepath)) { int filelen = (int)IOBinaryOperation.fileLength(filepath); if (filelen != (FinalConst.Len_Sence_Pack + 16)) { return(false); } //PresetLoadData = IOBinaryOperation.readBinaryFile(filepath, filelen); CoreData.SetLocalPreset(IOBinaryOperation.readBinaryFile(filepath, filelen)); Result = true; } } return(Result); }
private void ExportMemoryToFile() { if (MessageBox.Show("Global Presets downloaded, are you sure to save as file?", "Save Global Presets as file", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { SaveDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory; SaveDialog.Filter = "MemoryExportFile(*.ept)|*.ept"; if (SaveDialog.ShowDialog() == true) { string FilePath = SaveDialog.FileName; IOBinaryOperation.writeBinaryToFile(FilePath, System.Text.Encoding.ASCII.GetBytes(FinalConst.MemoryHeader)); byte[] temp = new byte[CoreData.m_memory.GetLength(0) * CoreData.m_memory.GetLength(1)]; int count = 0; for (int i = 0; i < CoreData.m_memory.GetLength(0); i++) { for (int j = 0; j < CoreData.m_memory.GetLength(1); j++) { temp[count++] = CoreData.m_memory[i, j]; } } IOBinaryOperation.writeBinaryToFile(FilePath, temp); } } }
private bool LoadMemoryFile() { bool Result = false; OpenDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory; OpenDialog.Filter = "MemoryExportFile(*.ept)|*.ept"; if (OpenDialog.ShowDialog() == true) { string filepath = OpenDialog.FileName; if (File.Exists(filepath)) { int filelen = (int)IOBinaryOperation.fileLength(filepath); if (filelen != (FinalConst.Len_Sence_Pack * 16 + 16)) { return(false); } MemoryLoadData = IOBinaryOperation.readBinaryFile(filepath, filelen); CoreData.SetMemory(MemoryLoadData); Result = true; } } return(Result); }