public Form1() { InitializeComponent(); comboBox1.Items.Clear(); foreach (ColorSpace cn in Dialog.XColors) { comboBox1.Items.Add(cn.Name); } dialogs1.SelectedChanging += new Dialogs.SelectEventHandler(dialogs1_SelectedChanging); dialogs1.SelectedChangingTL += new Dialogs.SelectEventHandlerTL(dialogs1_SelectedChangingTL); dialogs1.SelectedChanged += new Dialogs.SelectEventHandler(dialogs1_SelectedChanged); dialogs1.SelectedChangedTL += new Dialogs.SelectEventHandlerTL(dialogs1_SelectedChangedTL); dialogs1.OnStateChanged += new Dialogs.StateChanged(dialogs1_OnStateChanged); updateStatusLabel(); attributesForPhrase = dialogs1.phraseAttributesCountGet; this.Text = "DMPRO"; this.FormClosing += new FormClosingEventHandler(Form1_FormClosing); this.Shown += Form1_Shown; PrepareHistoryMenu(OpenFileHistory.DHistory); OpenFileHistory.OnUpdate += new OpenFileHistory.HistoryUpdated(PrepareHistoryMenu); dialogs1.TreeOperationMode = checkBox1.Checked = true; // init empty container jzip.Container container = new jzip.Container(null); Dialog dlg = new Dialog(container); dialogs1.dlg = new DBacklog(dlg); }
public Dialogs(jzip.Container imageContainer) { SetPhraseAttributesCount(4); InitializeComponent(); #if !PocketPC this.DoubleBuffered = true; this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.Opaque, true); this.SetStyle(ControlStyles.ResizeRedraw, true); #endif this.imageContainer = imageContainer; dlginstance = new DBacklog(new Dialog(imageContainer)); }
public void Clear() { FocusedEditPhrase = -1; FocusedPhrase = -1; FocusedTimeline = -1; FocusedEditTimeline = -1; dlg.Clear(); dlg.ClearHistory(); if (imageContainer != null) { imageContainer.Dispose(); File.Delete(imageContainer.FileName); } imageContainer = new jzip.Container(); dlg = new DBacklog(new Dialog(imageContainer)); SelectedChanged.Invoke(null); }
public void LoadJsFile(string path) { loading = true; updateStatusLabel(); this.Refresh(); string json = string.Empty; bool encoded = false; try { string workingFile = null; using (System.IO.Stream sp = new FileStream(path, FileMode.Open, FileAccess.Read)) { int a = sp.ReadByte(); int b = sp.ReadByte(); if (encoded = (a == 0xae && (b == 0xfe || b == 0xfa)) || (a == 0x9e && b == 0x3f)) { int fixedLength = 0; if (b == 0xfa || (a == 0x9e && b == 0x3f)) { byte[] jslength = new byte[4]; if (sp.Read(jslength, 0, 4) != 4) { throw new Exception("file corrupted."); } fixedLength = BitConverter.ToInt32(jslength, 0); sp.Seek(6, SeekOrigin.Begin); } else if (b == 0xfe) { fixedLength = ((int)sp.Length) - 2; sp.Seek(2, SeekOrigin.Begin); } string pwd_p = PasswordRequest(); if (pwd_p == null) { return; } DialogMaker.SecurityStream sec = new DialogMaker.SecurityStream(sp, pwd_p); if (!(a == 0x9e && b == 0x3f))//not zip encoded { using (MemoryStream ms = new MemoryStream()) { sec.CopyTo(ms); json = Encoding.UTF8.GetString(ms.GetBuffer(), 0, fixedLength); } sec.Close(); sec = null; //!!! LastLoadedEncoded = true; } else { workingFile = Path.GetTempFileName(); using (FileStream fs = new FileStream(workingFile, FileMode.Create)) { sec.CopyTo(fs); fs.Flush(); fs.SetLength(fixedLength); } LastLoadedEncoded = true; } } else if ((a == 'P' && b == 'K')) { workingFile = Path.GetTempFileName(); sp.Seek(0, SeekOrigin.Begin); using (FileStream fs = new FileStream(workingFile, FileMode.Create)) { sp.CopyTo(fs); } } else { sp.Seek(0, SeekOrigin.Begin); StreamReader sr = new StreamReader(sp, Encoding.UTF8); json = sr.ReadToEnd(); sr.Close(); //!!!! LastLoadedEncoded = false; } } //string json = sr.ReadToEnd();//System.IO.File.ReadAllText(path, Encoding.UTF8); //sr.Close(); //!!! LastLoadedJson = path; //Dialog dlg = Newtonsoft.Json.JsonConvert.DeserializeObject(json, typeof(Dialog)) as Dialog; //dialogs1.Clear(); jzip.Container container = new jzip.Container(workingFile); Dialog dlg = new Dialog(container); if (workingFile == null) { Newtonsoft.Json.JsonConvert.PopulateObject(json, dlg); } else { container.ExtractLinkedData(dlg); } foreach (var item in dlg.phrases) { if (item._attributes == null) { item._attributes = new byte[attributesForPhrase]; } } dialogs1.dlg = new DBacklog(dlg); dialogs1.imageContainer = container; this.Text = "DMPRO \"" + System.IO.Path.GetFileName(path) + "\""; dialogs1.Changed = false; OpenFileHistory.DHistory.Push(path); this.Refresh(); } catch (Exception exc) { if (!string.IsNullOrEmpty(json)) { string failOverPath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + "_failover_" + Path.GetExtension(path)); if (encoded) { try { File.WriteAllText(failOverPath, json, Encoding.UTF8); } catch { failOverPath = Path.Combine(Path.GetFileNameWithoutExtension(path) + "_failover_" + Path.GetExtension(path)); File.WriteAllText(failOverPath, json, Encoding.UTF8); } } else { failOverPath = null; } System.Windows.Forms.MessageBox.Show( string.Format("Error parsing saved dialog.\r\n{0} \r\n json saved as: {1}", exc.Message, failOverPath ?? "not saved"), "open file error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { System.Windows.Forms.MessageBox.Show( string.Format("Error occured while loading: {0}", exc.Message), "open file error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } finally { json = null; loading = false; updateStatusLabel(); } GC.Collect(); System.Threading.Thread.Sleep(100); GC.Collect(); System.Threading.Thread.Sleep(100); }