Ejemplo n.º 1
0
 void RemoveSauce()
 {
     sauce = null;
     if (!directSave)
     {
         return;
     }
     if (document != null)
     {
         document.Sauce      = null;
         document.IsModified = true;
     }
     else
     {
         bool hasSauce;
         using (var ms = new MemoryStream())
         {
             using (var stream = file.Open(FileMode.Open))
             {
                 var ss = new SauceStream(stream);
                 hasSauce = ss.Sauce != null;
                 if (hasSauce)
                 {
                     ss.WriteTo(ms);
                 }
             }
             if (hasSauce)
             {
                 file.Delete();
                 ms.Flush();
                 ms.Seek(0, SeekOrigin.Begin);
                 using (var newfile = file.Open(FileMode.CreateNew))
                 {
                     ms.WriteTo(newfile);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        public void ReloadFile(bool hasSavePermissions, bool focus, bool checkModifications)
        {
            if (!shouldReload)
            {
                return;
            }

            if (checkModifications && FileModifiedDialog.Show(this) != DialogResult.Ok)
            {
                return;
            }

            EtoFileInfo file = fileList.SelectedFile;

            if (file != null)
            {
                //Console.WriteLine ("Reloading file: {0}, format:{1}", file.Name, currentFormat != null ? currentFormat.GetType () : null);
                if (file != currentFile)
                {
                    currentFormat = null;
                }
                currentFile = file;
                Format format = currentFormat ?? Settings.Infos.FindFormat(file.FullName, "character", "ansi");
                if (format != null)
                {
                    try
                    {
                        var stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
                        LoadFile(file.FullName, stream, format, EditMode, false, hasSavePermissions);
                        if (focus)
                        {
                            padpanel.Content.Focus();
                        }
                    }
                    catch (Exception ex)
                    {
                        SetDocument(null);
                        MessageBox.Show(this, string.Format("Error loading file '{0}'.  {1}", file.FullName, ex.Message));
#if DEBUG
                        Debug.Print("Error loading: {0}", ex);
                        throw;
#endif
                    }
                }
            }
        }