private static void Compress(byte[] data, int offset, bool twice, int limit) { byte[] compData = Codec.Compress(data, twice, true); string info = CodecControl.FormatCompressedChunkInfo("New data", offset, compData.Length, data.Length); string oldInfo; try { int oldCompSize = Context.Game.GetCompressedChunkLength(offset); int oldUncompSize = Context.Game.Decompress(offset, twice).Length; oldInfo = CodecControl.FormatCompressedChunkInfo("Old data", offset, oldCompSize, oldUncompSize); } catch (InvalidDataException) { oldInfo = $"Cannot decompress data at {offset:X}." + Environment.NewLine; } info = oldInfo + Environment.NewLine + info; if (offset + compData.Length > limit) { info += Environment.NewLine + "Not enough room to fit the new data. Operation cancelled."; UITools.ShowError(info); } else if (UITools.ShowInfo(info, MessageBoxButtons.OKCancel) == DialogResult.OK) { Context.Game.InsertData(compData, offset); } }
public static void ImportData(BulkImportDataAction setDataMethod, params string[] filePaths) { try { for (int i = 0; i < filePaths.Length; i++) { setDataMethod(i, filePaths[i]); } } catch (UnauthorizedAccessException ex) { UITools.ShowError(ex.Message); } catch (IOException ex) { UITools.ShowError(ex.Message); } catch (ArgumentException ex) { UITools.ShowError(ex.Message); } catch (InvalidDataException ex) { UITools.ShowError(ex.Message); } }
public static void ExportData(Action <string> exportMethod, string filePath) { try { exportMethod(filePath); } catch (UnauthorizedAccessException ex) { UITools.ShowError(ex.Message); } catch (IOException ex) { UITools.ShowError(ex.Message); } catch (InvalidDataException ex) { UITools.ShowError(ex.Message); } }