Example #1
0
        /* The basic file parsing function */
        public Error parse_file(string filename, bool build_path = true)
        {
            string path = "";

            if (build_path)
            {
                path = Misc.path_build(Misc.ANGBAND_DIR_EDIT, filename + ".txt");
            }
            else
            {
                path = filename;
            }

            FileStream fs = File.OpenRead(path);

            StreamReader sr          = new StreamReader(fs);
            int          line_number = 0;

            while (!sr.EndOfStream)
            {
                string line = sr.ReadLine();
                line_number++;
                if (Parse(line) != Error.NONE)
                {
                    throw new Exception("Error parsing file!");
                }
            }

            fs.Close();

            return(Error.NONE);
        }
Example #2
0
        static void show_splashscreen(Game_Event.Event_Type type, Game_Event data, object user)
        {
            //ang_file *fp;

            //char buf[1024];

            /*** Verify the "news" file ***/

            string buf = Misc.path_build(Misc.ANGBAND_DIR_FILE, "news.txt");

            if (!File.Exists(buf))
            {
                //char why[1024];

                /* Crash and burn */
                string why = "Cannot access the '" + buf + "' file!";

                throw new NotImplementedException();                 //<-- Uncomment below and remove this
                //init_angband_aux(why);
            }


            /*** Display the "news" file ***/

            Term.clear();

            /* Open the News file */
            buf = Misc.path_build(Misc.ANGBAND_DIR_FILE, "news.txt");             //Didn't we just do this?
            FileStream   fp = File.OpenRead(buf);
            StreamReader sr = new StreamReader(fp);

            Misc.text_out_hook = Utilities.text_out_to_screen;

            /* Dump */
            //if (fp)
            //{
            /* Dump the file to the screen */
            while (!sr.EndOfStream)
            {
                buf = sr.ReadLine();
                //We are skipping the version stuff, we will do that later I gues...
                //No big deal if we skip it, right?
                //string version_marker = strstr(buf, "$VERSION");
                //if (version_marker)
                //{
                //    ptrdiff_t pos = version_marker - buf;
                //    strnfmt(version_marker, sizeof(buf) - pos, "%-8s", buildver);
                //}

                Utilities.text_out_e("{0}", buf);
                Utilities.text_out("\n");
            }

            fp.Close();
            //}

            /* Flush it */
            Term.fresh();
        }
Example #3
0
        /*
         * Process the player name and extract a clean "base name".
         *
         * If "sf" is true, then we initialize "savefile" based on player name.
         *
         * Some platforms (Windows, Macintosh, Amiga) leave the "savefile" empty
         * when a new character is created, and then when the character is done
         * being created, they call this function to choose a new savefile name.
         *
         * This also now handles the turning on and off of the automatic
         * sequential numbering of character names with Roman numerals.
         */
        public static void process_player_name(bool sf)
        {
            /* Process the player name */
            //Nick: Let's just assume it's acceptable
            //for (int i = 0; i < Player.Player_Other.instance.full_name.Length; i++)
            //{
            //    char c = Player.Player_Other.instance.full_name[i];

            //    /* No control characters */
            //    if (iscntrl((unsigned char)c))
            //    {
            //        /* Illegal characters */
            //        quit_fmt("Illegal control char (0x%02X) in player name", c);
            //    }

            //    /* Convert all non-alphanumeric symbols */
            //    if (!isalpha((unsigned char)c) && !isdigit((unsigned char)c)) c = '_';

            //    /* Build "base_name" */
            //    op_ptr.base_name[i] = c;
            //}

            //#if defined(WINDOWS)

            //    /* Max length */
            //    if (i > 8) i = 8;

            //#endif

            /* Terminate */
            //op_ptr.base_name[i] = '\0';

            /* Require a "base" name */
            if (Player_Other.instance.base_name == null || Player_Other.instance.base_name.Length == 0)
            {
                Player_Other.instance.base_name = "PLAYER";
            }


            /* Pick savefile name if needed */
            if (sf)
            {
                //char temp[128];

                //#if defined(SET_UID)
                //        /* Rename the savefile, using the player_uid and base_name */
                //        strnfmt(temp, sizeof(temp), "%d.%s", player_uid, op_ptr.base_name);
                //#else
                /* Rename the savefile, using the base name */
                //strnfmt(temp, sizeof(temp), "%s", op_ptr.base_name);
                //#endif

                /* Build the filename */
                savefile = Misc.path_build(Misc.ANGBAND_DIR_SAVE, Player_Other.instance.base_name);
            }
        }
Example #4
0
        /*
         * Process the user pref file with the given name.
         * "quiet" means "don't complain about not finding the file.
         *
         * 'user' should be true if the pref file loaded is user-specific and not
         * a game default.
         *
         * Returns true if everything worked OK, false otherwise
         */
        public static bool process_pref_file(string name, bool quiet, bool user)
        {
            //Nick: Rewritten from scratch, since io is so different from C
            string path = Misc.path_build(Misc.ANGBAND_DIR_PREF, name);

            if (!File.Exists(path))
            {
                path = Misc.path_build(Misc.ANGBAND_DIR_USER, name);
                if (!File.Exists(path))
                {
                    if (!quiet)
                    {
                        Utilities.msg("Can not open " + path + ".");
                    }
                    return(false);
                }
            }

            FileStream f = null;

            try {
                f = File.OpenRead(path);
            } catch {
                if (!quiet)
                {
                    Utilities.msg("Can not open " + path + ".");
                }
                return(false);
            } finally {
                if (f != null)
                {
                    f.Close();                     //Just wanted to see if we could open it before proceeding...
                }
            }


            Parser p = init_parse_prefs(user);

            Parser.Error e = p.parse_file(path, false);

            finish_parse_prefs(p);
            p.Destroy();

            return(e == Parser.Error.NONE);

            //Below I wrote until I realized that there exists a Parser.ParseFile...
            //StreamReader sr = new StreamReader(f);


            //while (!sr.EndOfStream)
            //{
            //    line_no++;

            //    e = p.Parse(line);
            //    if (e != Parser.Error.NONE)
            //    {
            //        print_error(buf, p);
            //        break;
            //    }
            //}
            //finish_parse_prefs(p);

            //f.Close();
            //p.Destroy();

            ///* Result */
            //return e == Parser.Error.NONE;


            //======================Original below for comparison
            //char buf[1024];

            //ang_file *f;
            //Parser p;
            //int e = 0;

            //int line_no = 0;

            ///* Build the filename */
            //path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, name);
            //if (!file_exists(buf))
            //    path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);

            //f = file_open(buf, MODE_READ, -1);
            //if (!f)
            //{
            //    if (!quiet)
            //        msg("Cannot open '%s'.", buf);
            //}
            //else
            //{
            //    char line[1024];

            //    p = init_parse_prefs(user);
            //    while (file_getl(f, line, sizeof line))
            //    {
            //        line_no++;

            //        e = parser_parse(p, line);
            //        if (e != Parser.Error.NONE)
            //        {
            //            print_error(buf, p);
            //            break;
            //        }
            //    }
            //    finish_parse_prefs(p);

            //    file_close(f);
            //    mem_free(p.priv);
            //    parser_destroy(p);
            //}

            ///* Result */
            //return e == Parser.Error.NONE;
        }