void InitializeLastUsedTypes() { if (initialized) { return; } try { ProtoMiddlerState.Deserialize(this); // cannot set values before OnLoad txtProtoFile.Text = ProtoFile; UpdateTypeList(); Application.ApplicationExit += (sender, e) => { try { // cannot use values from UI while exiting ProtoMiddlerState.Serialize(this); } catch { } }; } catch { } initialized = true; }
void bnDecodeAs_Click(object sender, EventArgs e) { MessageType = (string)cbType.SelectedItem; ProtoFile = txtProtoFile.Text; if (!string.IsNullOrWhiteSpace(ProtoFile) && !string.IsNullOrWhiteSpace(MessageType)) { Data = ProtoBufUtil.DecodeWithProto(ProtobufBytes, MessageType, ProtoFile); } ProtoMiddlerState.Serialize(this); }
internal static void Serialize(ProtoBufInspectorControl @this, string filename = TempFile) { var state = new ProtoMiddlerState { LastUsedPath = @this.ProtoFile, LastUsedTypes = @this._lastUsedTypes, }; var file = Path.GetTempFileName(); using (var fs = File.OpenWrite(file)) { var ds = new DataContractSerializer(typeof(ProtoMiddlerState)); ds.WriteObject(fs, state); } File.Replace(file, Path.Combine(Path.GetTempPath(), filename), null); }
internal static void Serialize(ProtoBufInspectorControl @this, string filename = TempFile) { var state = new ProtoMiddlerState { LastUsedPath = @this.ProtoFile, LastUsedTypes = @this._lastUsedTypes, }; var file = Path.GetTempFileName(); using (var fs = File.OpenWrite(file)) { var ds = new DataContractSerializer(typeof (ProtoMiddlerState)); ds.WriteObject(fs, state); } File.Replace(file, Path.Combine(Path.GetTempPath(), filename), null); }