Esempio n. 1
0
        public static FileInfo GetWatchSaveFileFromUser(string currentFile)
        {
            var sfd = new SaveFileDialog();

            if (!string.IsNullOrWhiteSpace(currentFile))
            {
                sfd.FileName         = Path.GetFileNameWithoutExtension(currentFile);
                sfd.InitialDirectory = Path.GetDirectoryName(currentFile);
            }
            else if (!(Global.Emulator is NullEmulator))
            {
                sfd.FileName         = PathManager.FilesystemSafeName(Global.Game);
                sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.WatchPathFragment, null);
            }
            else
            {
                sfd.FileName         = "NULL";
                sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.WatchPathFragment, null);
            }

            sfd.Filter           = "Watch Files (*.wch)|*.wch|All Files|*.*";
            sfd.RestoreDirectory = true;
            var result = sfd.ShowHawkDialog();

            if (result != DialogResult.OK)
            {
                return(null);
            }

            return(new FileInfo(sfd.FileName));
        }
Esempio n. 2
0
        private void BrowseBtn_Click(object sender, EventArgs e)
        {
            string filename         = "";
            string initialDirectory = Config.PathEntries.MultiDiskAbsolutePath();

            if (!Game.IsNullInstance())
            {
                filename = NameBox.Text;
                if (string.IsNullOrWhiteSpace(filename))
                {
                    filename = Path.ChangeExtension(Game.FilesystemSafeName(), ".xml");
                }

                initialDirectory = Path.GetDirectoryName(filename);
            }

            using var sfd = new SaveFileDialog
                  {
                      FileName         = filename,
                      InitialDirectory = initialDirectory,
                      Filter           = new FilesystemFilterSet(new FilesystemFilter("XML Files", new[] { "xml" })).ToString()
                  };

            var result = sfd.ShowHawkDialog();

            if (result != DialogResult.Cancel)
            {
                NameBox.Text = sfd.FileName;
            }
        }
Esempio n. 3
0
        private FileInfo GetFileFromUser()
        {
            var sfd = new SaveFileDialog();

            if (_logFile == null)
            {
                sfd.FileName         = PathManager.FilesystemSafeName(Global.Game) + ".log";
                sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.LogPathFragment, null);
            }
            else if (!string.IsNullOrWhiteSpace(_logFile.FullName))
            {
                sfd.FileName         = PathManager.FilesystemSafeName(Global.Game);
                sfd.InitialDirectory = Path.GetDirectoryName(_logFile.FullName);
            }
            else
            {
                sfd.FileName         = Path.GetFileNameWithoutExtension(_logFile.FullName);
                sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.LogPathFragment, null);
            }

            sfd.Filter           = "Log Files (*.log)|*.log|Text Files (*.txt)|*.txt|All Files|*.*";
            sfd.RestoreDirectory = true;
            var result = sfd.ShowHawkDialog();

            if (result == DialogResult.OK)
            {
                return(new FileInfo(sfd.FileName));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 4
0
        private FileInfo GetSaveFileFromUser()
        {
            var sfd = new SaveFileDialog();

            if (!string.IsNullOrWhiteSpace(LuaImp.ScriptList.Filename))
            {
                sfd.FileName         = Path.GetFileNameWithoutExtension(LuaImp.ScriptList.Filename);
                sfd.InitialDirectory = Path.GetDirectoryName(LuaImp.ScriptList.Filename);
            }
            else if (Global.Game != null)
            {
                sfd.FileName         = PathManager.FilesystemSafeName(Global.Game);
                sfd.InitialDirectory = PathManager.GetLuaPath();
            }
            else
            {
                sfd.FileName         = "NULL";
                sfd.InitialDirectory = PathManager.GetLuaPath();
            }

            sfd.Filter           = "Lua Session Files (*.luases)|*.luases|All Files|*.*";
            sfd.RestoreDirectory = true;
            var result = sfd.ShowHawkDialog();

            if (result != DialogResult.OK)
            {
                return(null);
            }

            return(new FileInfo(sfd.FileName));
        }
Esempio n. 5
0
        public static void SaveAsFile(this Bitmap bitmap, IGameInfo game, string suffix, string systemId, PathEntryCollection paths, IWin32Window owner)
        {
            using var sfd = new SaveFileDialog
                  {
                      FileName         = $"{game.FilesystemSafeName()}-{suffix}",
                      InitialDirectory = paths.ScreenshotAbsolutePathFor(systemId),
                      Filter           = FilesystemFilterSet.Screenshots.ToString(),
                      RestoreDirectory = true
                  };

            var result = sfd.ShowHawkDialog(owner);

            if (result != DialogResult.OK)
            {
                return;
            }

            var         file = new FileInfo(sfd.FileName);
            ImageFormat i;
            string      extension = file.Extension.ToUpper();

            switch (extension)
            {
            default:
            case ".PNG":
                i = ImageFormat.Png;
                break;

            case ".BMP":
                i = ImageFormat.Bmp;
                break;
            }

            bitmap.Save(file.FullName, i);
        }
Esempio n. 6
0
        private void NewScriptMenuItem_Click(object sender, EventArgs e)
        {
            var sfd = new SaveFileDialog
            {
                InitialDirectory = !string.IsNullOrWhiteSpace(LuaImp.ScriptList.Filename) ?
                                   Path.GetDirectoryName(LuaImp.ScriptList.Filename) :
                                   PathManager.MakeAbsolutePath(Global.Config.PathEntries.LuaPathFragment, null),
                DefaultExt = ".lua",
                FileName   = !string.IsNullOrWhiteSpace(LuaImp.ScriptList.Filename) ?
                             Path.GetFileNameWithoutExtension(LuaImp.ScriptList.Filename) :
                             Path.GetFileNameWithoutExtension(Global.Game.Name),
                OverwritePrompt = true,
                Filter          = "Lua Scripts (*.lua)|*.lua|All Files (*.*)|*.*"
            };

            var result = sfd.ShowHawkDialog();

            if (result == DialogResult.OK &&
                !string.IsNullOrWhiteSpace(sfd.FileName))
            {
                string defaultTemplate = "while true do\n\temu.frameadvance();\nend";
                File.WriteAllText(sfd.FileName, defaultTemplate);
                LuaImp.ScriptList.Add(new LuaFile(Path.GetFileNameWithoutExtension(sfd.FileName), sfd.FileName));
                UpdateDialog();
                Process.Start(new ProcessStartInfo
                {
                    Verb     = "Open",
                    FileName = sfd.FileName
                });
            }
        }
Esempio n. 7
0
        public static FileInfo SaveFileDialog(string currentFile, string path, string fileType, string fileExt)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            var sfd = new SaveFileDialog
            {
                FileName = !string.IsNullOrWhiteSpace(currentFile)
                                        ? Path.GetFileName(currentFile)
                                        : $"{PathManager.FilesystemSafeName(Global.Game)}.{fileExt}",
                InitialDirectory = path,
                Filter           = string.Format("{0} (*.{1})|*.{1}|All Files|*.*", fileType, fileExt),
                RestoreDirectory = true,
            };

            var result = sfd.ShowHawkDialog();

            if (result != DialogResult.OK)
            {
                return(null);
            }

            return(new FileInfo(sfd.FileName));
        }
Esempio n. 8
0
        public static FileInfo SaveFileDialog(string currentFile, string path, string fileType, string fileExt)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            using var sfd = new SaveFileDialog
                  {
                      FileName = !string.IsNullOrWhiteSpace(currentFile)
                                        ? Path.GetFileName(currentFile)
                                        : $"{GlobalWin.Game.FilesystemSafeName()}.{fileExt}",
                      InitialDirectory = path,
                      Filter           = new FilesystemFilterSet(new FilesystemFilter(fileType, new[] { fileExt })).ToString(),
                      RestoreDirectory = true
                  };

            var result = sfd.ShowHawkDialog();

            if (result != DialogResult.OK)
            {
                return(null);
            }

            return(new FileInfo(sfd.FileName));
        }
Esempio n. 9
0
        private void BrowseBtn_Click(object sender, EventArgs e)
        {
            string filename         = "";
            string initialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MultiDiskBundlesFragment, "Global_NULL");

            if (!Global.Game.IsNullInstance)
            {
                filename = NameBox.Text;
                if (string.IsNullOrWhiteSpace(filename))
                {
                    filename = Path.ChangeExtension(PathManager.FilesystemSafeName(Global.Game), ".xml");
                }

                initialDirectory = Path.GetDirectoryName(filename);
            }

            var sfd = new SaveFileDialog
            {
                FileName         = filename,
                InitialDirectory = initialDirectory,
                Filter           = "xml (*.xml)|*.xml|All Files|*.*"
            };

            var result = sfd.ShowHawkDialog();

            if (result != DialogResult.Cancel)
            {
                NameBox.Text = sfd.FileName;
            }
        }
Esempio n. 10
0
        public bool SaveMacroAs(MovieZone macro)
        {
            using var dialog = new SaveFileDialog
                  {
                      InitialDirectory = SuggestedFolder(),
                      FileName         = macro.Name,
                      Filter           = "Movie Macros (*.bk2m)|*.bk2m|All Files|*.*"
                  };

            // Create directory?
            bool create = false;

            if (!Directory.Exists(SuggestedFolder()))
            {
                Directory.CreateDirectory(SuggestedFolder());
                create = true;
            }

            DialogResult result = dialog.ShowHawkDialog();

            if (result != DialogResult.OK)
            {
                if (create)
                {
                    Directory.Delete(dialog.InitialDirectory);
                }

                return(false);
            }

            macro.Save(dialog.FileName);
            Config.RecentMacros.Add(dialog.FileName);

            return(true);
        }
Esempio n. 11
0
        public static FileInfo GetCheatSaveFileFromUser(string currentFile)
        {
            var sfd = new SaveFileDialog();

            if (!string.IsNullOrWhiteSpace(currentFile))
            {
                sfd.FileName = Path.GetFileNameWithoutExtension(currentFile);
            }
            else if (!(Global.Emulator is NullEmulator))
            {
                sfd.FileName = PathManager.FilesystemSafeName(Global.Game);
            }

            sfd.InitialDirectory = PathManager.GetCheatsPath(Global.Game);
            sfd.Filter           = "Cheat Files (*.cht)|*.cht|All Files|*.*";
            sfd.RestoreDirectory = true;
            var result = sfd.ShowHawkDialog();

            if (result != DialogResult.OK)
            {
                return(null);
            }

            return(new FileInfo(sfd.FileName));
        }
Esempio n. 12
0
        public void SaveFile()
        {
            string path = PathManager.MakeAbsolutePath(
                Global.Config.PathEntries[Global.Emulator.SystemId, "Screenshots"].Path,
                Global.Emulator.SystemId);

            var di = new DirectoryInfo(path);

            if (!di.Exists)
            {
                di.Create();
            }

            using var sfd = new SaveFileDialog
                  {
                      FileName         = $"{PathManager.FilesystemSafeName(Global.Game)}-Palettes",
                      InitialDirectory = path,
                      Filter           = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*",
                      RestoreDirectory = true
                  };

            var result = sfd.ShowHawkDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            var file = new FileInfo(sfd.FileName);
            var b    = BMP;

            ImageFormat i;
            string      extension = file.Extension.ToUpper();

            switch (extension)
            {
            default:
            case ".PNG":
                i = ImageFormat.Png;
                break;

            case ".BMP":
                i = ImageFormat.Bmp;
                break;
            }

            b.Save(file.FullName, i);
        }
Esempio n. 13
0
        private void BrowseBtn_Click(object sender, EventArgs e)
        {
            var sfd = new SaveFileDialog
            {
                FileName         = Path.ChangeExtension(GlobalWin.MainForm.CurrentlyOpenRom, ".xml"),
                InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries["Global_NULL", "ROM"].Path, "Global_NULL"),
                Filter           = "xml (*.xml)|*.xml|All Files|*.*"
            };

            var result = sfd.ShowHawkDialog();

            if (result != DialogResult.Cancel)
            {
                NameBox.Text = sfd.FileName;
            }
        }
Esempio n. 14
0

        
Esempio n. 15
0
        private void BrowseBtn_Click(object sender, EventArgs e)
        {
            string movieFolderPath = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null);

            // Create movie folder if it doesn't already exist
            try
            {
                if (!Directory.Exists(movieFolderPath))
                {
                    Directory.CreateDirectory(movieFolderPath);
                }
            }
            catch (Exception movieDirException)
            {
                if (movieDirException is IOException ||
                    movieDirException is UnauthorizedAccessException ||
                    movieDirException is PathTooLongException
                    )
                {
                    //TO DO : Pass error to user?
                }
                else
                {
                    throw;
                }
            }

            var sfd = new SaveFileDialog
            {
                InitialDirectory = movieFolderPath,
                DefaultExt       = "." + Global.MovieSession.Movie.PreferredExtension,
                FileName         = RecordBox.Text,
                OverwritePrompt  = false,
                Filter           = "Movie Files (*." + Global.MovieSession.Movie.PreferredExtension + ")|*." + Global.MovieSession.Movie.PreferredExtension + "|All Files|*.*"
            };

            var result = sfd.ShowHawkDialog();

            if (result == DialogResult.OK &&
                !string.IsNullOrWhiteSpace(sfd.FileName))
            {
                RecordBox.Text = sfd.FileName;
            }
        }
Esempio n. 16
0
        private void BrowseBtn_Click(object sender, EventArgs e)
        {
            string movieFolderPath = _config.PathEntries.MovieAbsolutePath();

            // Create movie folder if it doesn't already exist
            try
            {
                if (!Directory.Exists(movieFolderPath))
                {
                    Directory.CreateDirectory(movieFolderPath);
                }
            }
            catch (Exception movieDirException)
            {
                if (movieDirException is IOException ||
                    movieDirException is UnauthorizedAccessException)
                {
                    //TO DO : Pass error to user?
                }
                else
                {
                    throw;
                }
            }

            var preferredExt = _movieSession.Movie?.PreferredExtension ?? "bk2";

            using var sfd = new SaveFileDialog
                  {
                      InitialDirectory = movieFolderPath,
                      DefaultExt       = $".{preferredExt}",
                      FileName         = RecordBox.Text,
                      OverwritePrompt  = false,
                      Filter           = new FilesystemFilterSet(new FilesystemFilter("Movie Files", new[] { preferredExt })).ToString()
                  };

            var result = sfd.ShowHawkDialog();

            if (result == DialogResult.OK &&
                !string.IsNullOrWhiteSpace(sfd.FileName))
            {
                RecordBox.Text = sfd.FileName;
            }
        }
Esempio n. 17
0
        private void BrowseBtn_Click(object sender, EventArgs e)
        {
            var sfd = new SaveFileDialog
            {
                InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null),
                DefaultExt       = "." + Global.MovieSession.Movie.PreferredExtension,
                FileName         = RecordBox.Text,
                OverwritePrompt  = false,
                Filter           = "Movie Files (*." + Global.MovieSession.Movie.PreferredExtension + ")|*." + Global.MovieSession.Movie.PreferredExtension + "|All Files|*.*"
            };

            var result = sfd.ShowHawkDialog();

            if (result == DialogResult.OK &&
                !string.IsNullOrWhiteSpace(sfd.FileName))
            {
                RecordBox.Text = sfd.FileName;
            }
        }
Esempio n. 18
0
        public void Screenshot()
        {
            using var sfd = new SaveFileDialog
                  {
                      FileName         = $"{Global.Game.Name.FilesystemSafeName()}-Nametables",
                      InitialDirectory = Global.Config.PathEntries.ScreenshotAbsolutePathFor("NES"),
                      Filter           = FilesystemFilterSet.Screenshots.ToString(),
                      RestoreDirectory = true
                  };

            var result = sfd.ShowHawkDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            var file = new FileInfo(sfd.FileName);

            using Bitmap b = new Bitmap(Width, Height);
            Rectangle rect = new Rectangle(new Point(0, 0), Size);

            DrawToBitmap(b, rect);

            ImageFormat i;
            string      extension = file.Extension.ToUpper();

            switch (extension)
            {
            default:
            case ".PNG":
                i = ImageFormat.Png;
                break;

            case ".BMP":
                i = ImageFormat.Bmp;
                break;
            }

            b.Save(file.FullName, i);
        }
Esempio n. 19
0
        public void Screenshot()
        {
            using var sfd = new SaveFileDialog
                  {
                      FileName         = $"{PathManager.FilesystemSafeName(Global.Game)}-Nametables",
                      InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries["NES", "Screenshots"].Path, "NES"),
                      Filter           = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*",
                      RestoreDirectory = true
                  };

            var result = sfd.ShowHawkDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            var file = new FileInfo(sfd.FileName);

            using (Bitmap b = new Bitmap(Width, Height))
            {
                Rectangle rect = new Rectangle(new Point(0, 0), Size);
                DrawToBitmap(b, rect);

                ImageFormat i;
                string      extension = file.Extension.ToUpper();
                switch (extension)
                {
                default:
                case ".PNG":
                    i = ImageFormat.Png;
                    break;

                case ".BMP":
                    i = ImageFormat.Bmp;
                    break;
                }

                b.Save(file.FullName, i);
            }
        }
Esempio n. 20
0
        public static FileInfo GetCdlSaveFileFromUser(string currentFile)
        {
            var sfd = new SaveFileDialog
            {
                Filter           = "Code Data Logger Files (*.cdl)|*.cdl|All Files|*.*",
                InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.LogPathFragment, null),
                RestoreDirectory = true
            };

            if (!string.IsNullOrWhiteSpace(currentFile))
            {
                sfd.FileName = Path.GetFileNameWithoutExtension(currentFile);
            }

            var result = sfd.ShowHawkDialog();

            if (result != DialogResult.OK)
            {
                return(null);
            }

            return(new FileInfo(sfd.FileName));
        }