private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { if (listBox1.SelectedItem == null) { richTextBox2.Text = ""; return; } if (Cache.UpdateCache(listBox1.SelectedItem.ToString()) == false) { WindowLog.Error("Main::LoadCache", "Error loading cache"); return; } PyObject cache = Cache.GetCache(listBox1.SelectedItem.ToString()); PyCachedObject obj = new PyCachedObject(); if (obj.Decode(cache) == false) { WindowLog.Error("Main::LoadCache", "Cannot decode the cache data"); return; } if (Program.cacheDataDisplayMode == "Pretty") { try { richTextBox2.Text = PrettyPrinter.Print(Unmarshal.Process <PyObject>(obj.cache.Data)); } catch (Exception) { WindowLog.Error("Main::LoadCache", "Cannot Unmarshal the cache data"); richTextBox2.Text = "Error"; } } else { richTextBox2.Text = ByteToString(obj.cache.Data); } WindowLog.Debug("Main::LoadCache", "Cache loaded"); }
private void button5_Click(object sender, EventArgs e) { if (listBox1.SelectedItem == null) { Message.Error("Main::SaveFile", "Debes elejir la cache a guardar"); return; } saveFileDialog1.Filter = "Archivos de cache(*.cache)|*.cache"; if (saveFileDialog1.ShowDialog() != DialogResult.OK) { return; } PyObject cache = Cache.GetCache(listBox1.SelectedItem.ToString()); PyCachedObject obj = new PyCachedObject(); if (obj.Decode(cache) == false) { Message.Error("Main::SaveFile", "No se pudo obtener la información correctamente"); return; } if (File.Exists(saveFileDialog1.FileName) == true) { try { File.Delete(saveFileDialog1.FileName); } catch (Exception) { } } FileStream fp = File.OpenWrite(saveFileDialog1.FileName); fp.Write(obj.cache.Data, 0, obj.cache.Data.Length); fp.Close(); WindowLog.Debug("Main::SaveFile", "Cache saved sucessful"); }
private void copiaDeSeguridadCompletaToolStripMenuItem_Click(object sender, EventArgs e) { if (Message.Ask("Main::CompleteBackup", "¿Seguro que deseas hacer una copia de seguridad de toda la cache? Esto puede llevar varios minutos") == DialogResult.No) { return; } folderBrowserDialog1.Description = "Elije la carpeta de destino"; if (folderBrowserDialog1.ShowDialog() == DialogResult.Cancel) { return; } bool asked = false; foreach (string name in cacheNames) { WindowLog.Debug("Main::CompleteBackup", "Saving cache " + name + " to file"); string filename = folderBrowserDialog1.SelectedPath + "/" + name + ".cache"; PyObject cache = Cache.GetCache(name); PyCachedObject obj = new PyCachedObject(); if (obj.Decode(cache) == false) { Message.Error("Main::CompleteBackup", "No se pudo obtener la información correctamente"); return; } if (File.Exists(filename) == true) { if (!asked) { if (Message.Ask("Main::CompleteBackup", "Uno o más archivos ya existen, ¿desea reemplazarlos?") == DialogResult.No) { WindowLog.Error("Main::CompleteBackup", "Cancelled by the user"); return; } } asked = true; try { File.Delete(filename); } catch (Exception) { } } FileStream fp = File.OpenWrite(filename); fp.Write(obj.cache.Data, 0, obj.cache.Data.Length); fp.Close(); WindowLog.Debug("Main::CompleteBackup", "Cache " + name + " saved correctly"); } Message.Info("Main::CompleteBackup", "Cache guardada en " + folderBrowserDialog1.SelectedPath + " con éxito"); }