public static void Open(LibertyV window, string filename)
        {
            RPF7File file   = null;
            Stream   stream = null;

            try
            {
                new ProgressWindow("Open", progress =>
                {
                    progress.SetMessage("Loading..");
                    progress.SetProgress(-1);
                    stream = File.OpenRead(filename);
                    file   = new RPF7File(stream, Path.GetFileName(filename), filename);
                }).Run();
            }
            catch (RPFParsingException ex)
            {
                MessageBox.Show(ex.Message, "Failed to load RPF", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (stream != null)
                {
                    stream.Close();
                }
                return;
            }
            window.LoadRPF(file);
        }
        public static void Open(LibertyV window)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "RAGE Package Format|*.rpf";
            openFileDialog.Title  = "Select a file";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                Open(window, openFileDialog.FileName);
            }
        }
Exemple #3
0
        public static void OpenRPF(FileEntry entry)
        {
            string   tempPath = Path.GetTempFileName();
            Stream   tempFile = new FileStream(tempPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite, 0x1000, FileOptions.DeleteOnClose);
            LibertyV window   = new LibertyV(new RPF7File(entry.Data.GetStream(), entry.Name), tempPath);

            window.ShowDialog();
            if (tempFile.Length > 0)
            {
                // Replace data
                entry.Data.Dispose();
                entry.Data = new ExternalFileStreamCreator(tempFile);
                entry.ViewItem.Update();
            }
            else
            {
                tempFile.Close();
            }
        }
        public static void SaveAs(LibertyV window)
        {
            string result = GUI.FileSaveSelection(Path.GetFileName(window.File.Filename));

            if (result == null)
            {
                return;
            }
            FileStream file = null;

            try
            {
                file = System.IO.File.Create(result);
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message, "Failed to open file for writing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ProgressWindow progress = new ProgressWindow("Saving", update => window.File.Write(file, update), true);

            try
            {
                progress.Run();
            }
            catch (OperationCanceledException)
            {
                // delete the file
                file.Close();
                System.IO.File.Delete(result);
                MessageBox.Show("Operation canceled.");
                return;
            }

            // Now open this file
            file.Seek(0, SeekOrigin.Begin);
            window.LoadRPF(new RPF7File(file, Path.GetFileName(result), result), true);
        }
        public static void Save(LibertyV window)
        {
            if (MessageBox.Show("Are you sure you want to save all changes?", "Save", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != System.Windows.Forms.DialogResult.Yes)
            {
                return;
            }
            string originalFilename = window.File.Filename;
            String filePath         = window.File.FilePath;

            // Write to temporary file
            string     tempFilePath = null;
            FileStream file         = null;

            if (filePath != null)
            {
                tempFilePath = filePath + "." + Path.GetRandomFileName();
                file         = System.IO.File.Create(tempFilePath);
            }
            else
            {
                // This is a temporary file, we need to open it with the right flags
                tempFilePath = window.TempOutputFile;
                file         = new FileStream(tempFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete);
            }

            ProgressWindow progress = new ProgressWindow("Saving", update => window.File.Write(file, update), true);

            try
            {
                progress.Run();
            }
            catch (OperationCanceledException)
            {
                // This operation cancelled
                if (filePath != null)
                {
                    // delete the file
                    file.Close();
                    System.IO.File.Delete(tempFilePath);
                }
                else
                {
                    // Well it is a temporary file, so we don't want to delete it, just make it empty again
                    file.SetLength(0);
                    file.Close();
                }
                MessageBox.Show("Operation canceled.");
                return;
            }

            file.SetLength(file.Position);

            if (filePath != null)
            {
                // Update the file and reopen it
                file.Close();
                window.CloseRPF(false);
                System.IO.File.Delete(filePath);
                System.IO.File.Move(tempFilePath, filePath);

                // Now load the file
                file = System.IO.File.Open(filePath, FileMode.Open);
                window.LoadRPF(new RPF7File(file, originalFilename, filePath), true);
            }
            else
            {
                // Notice: We are not going to use the file that we just wrote, because if we are going to write it again, we will read and write from the same file
                // We waste little bit resources right now (because we doesn't release the old resource because we aren't using the new one), but it isn't so bad
                file.Close();
            }
        }
 public static bool CanOpen(LibertyV window)
 {
     return(window.TempOutputFile == null);
 }
 public static bool CanSave(LibertyV window)
 {
     return(window.File != null);
 }
 public static void Exit(LibertyV window)
 {
     window.Close();
 }
 public static void Close(LibertyV window)
 {
     window.CloseRPF();
 }