XNA Creators Club Online
Page 1 of 1 (11 items)
Sort Posts: Previous Next

Cant create or write to the Xbox HD

Last post 04-24-2008 6:32 PM by kewlniss. 10 replies.
  • 04-23-2008 6:48 PM

    Cant create or write to the Xbox HD

    both of these lines of code crash my game... only when run on my 360!... no problem running on windows

    Stream stream = File.Create("bfbk.nik");

    and

    StreamWriter sw = new StreamWriter("Decks//Deck1.txt");

    ive tried all sorts of things with no luck!.... im thinking it might be some sort of setting im ignorant to...

    oh im also using

    using System.IO;

    which has been working fine with reading files.... so i dont think thats it but.... im reallly stuck!

    :) www.windjestergames.net ;)
  • 04-23-2008 6:57 PM In reply to

    Re: Cant create or write to the Xbox HD

    Might want to look at this page of the documentation: http://msdn2.microsoft.com/en-us/library/bb199073.aspx. It covers how to do all the file management stuff on the Xbox.

    Edit: And those also work on Windows, so you don't need to write different file manipulation stuff for each platform.
  • 04-24-2008 1:52 PM In reply to

    Re: Cant create or write to the Xbox HD

    I had trouble with this for AGES - I was making a Pong implementation (yes the 10 millionth XNA pong implementation) for my coursework, and trying to load / save high scores to a storage device.

    The problem is that the Xbox 360 doesn't support System.IO, so you really have to use Xml Serialisation.

    It's not TOO difficult to get your head around though, just look at the appropriate MSDN documentation - there's also a nice tutorial about Xml Serialisation on ziggyware.com, that seemed to help me.

    Hope that helps!
    Visit my blog!

    http://lukemeister-lukemeister.blogspot.com/

    XNA Developer
  • 04-24-2008 2:04 PM In reply to

    Re: Cant create or write to the Xbox HD

    Not even close to being true... take a look at the samples that Nick linked to - they all use System.IO

    The main difference is that you need to use the storage APIs to get hold of the file - but once you have that then (most of) System.IO will work fine.

    I suspect that XML Serialization sits on top of System.IO anyway - though who knows what the CF framework does.



    The ZBuffer News and information for XNA

    Please read the forum FAQs - Bug reporting
  • 04-24-2008 2:27 PM In reply to

    Re: Cant create or write to the Xbox HD

    LukeMeister360:
    The problem is that the Xbox 360 doesn't support System.IO, so you really have to use Xml Serialisation.


    That's not correct. To reiterate what the ZMan said, it's not that the API doesn't exist, it's that you cannot just access the file system like you can in Windows. The Xbox requires you to use the storage APIs to find the proper directory or file and then you can use System.IO with a StreamWriter or whatever to actually write the data. It's more of a protection layer to keep people from trying to mess with your console's file system and delete necessary files or add malicious/inappropriate files to sytem directories.

    And like I mentioned you can use the same storage API calls on both Windows and Xbox 360, so you don't have to do multiple code branches for saving. That document also will explain where Windows stores the directories for your Windows game in case you want to know exactly where it is saving the files.
  • 04-24-2008 2:44 PM In reply to

    Re: Cant create or write to the Xbox HD

    Yes I phrased that extremely badly (sorry!) - what I meant was that to use stuff like StreamWriter / Reader you have to use the XNA Storage API to access a storage device and open / create a Storage Container. THEN you can use StreamWriter / XmlWriter whatever to store/load content. And it's really useful that the same code works in Windows too, as it just creates a folder in your Documents / My Documents folder (depending on XP/Vista)
    Visit my blog!

    http://lukemeister-lukemeister.blogspot.com/

    XNA Developer
  • 04-24-2008 3:44 PM In reply to

    Re: Cant create or write to the Xbox HD

    Nick Gravelyn:
    To reiterate what the ZMan said, it's not that the API doesn't exist, it's that you cannot just access the file system like you can in Windows. The Xbox requires you to use the storage APIs to find the proper directory or file and then you can use System.IO with a StreamWriter or whatever to actually write the data.

    The real issue is that there is no "current directory" on Xbox 360. On the desktop, you are used to accessing files using relative paths -- relative to the current directory. On Xbox 360, there is no current directory, so all paths must be specified as absolute paths. It's the same thing as Windows Mobile, if you've ever programmed for that.

    Specifying a path like "file.txt" is meaningless when you have no notion of a current directory because you haven't told the OS where to find the file, or even what drive (storage device) it's on.

    We aren't protecting you from anything; it's just how the file system works. Lots of file systems work this way -- but for people who are used to having a current directory in Windows XP and Windows Vista (and their predecessors), it's a bit unusual at first.

    Stephen Styrchak | XNA Game Studio Developer
  • 04-24-2008 3:48 PM In reply to

    Re: Cant create or write to the Xbox HD

    Stephen Styrchak:
    The real issue is that there is no "current directory" on Xbox 360.


    Wow, I had no idea.

    As a related question, does the Xbox 360 have the notion of a "root" drive such that a path like "\Dir\File.txt" would be acceptable (assuming Dir\File.Txt actually exists)? I would assume not since there is the case that the user has no storage device, but I wanted to check anyway.
  • 04-24-2008 4:14 PM In reply to

    Re: Cant create or write to the Xbox HD

    Nick Gravelyn:
    As a related question, does the Xbox 360 have the notion of a "root" drive such that a path like "\Dir\File.txt" would be acceptable


    No. Again that would require some state to know what the current drive is, and the 360 has no such concept.

    Filenames on this sort of device must always be a fully specified path, first telling what device, then the location on that device, and finally the name of the file. Unlike on Windows, you can't leave out any part of this specification, because the OS has no idea what to fill in the missing pieces with.
    XNA Framework Developer - blog - homepage
  • 04-24-2008 4:28 PM In reply to

    Re: Cant create or write to the Xbox HD

    That's what I figured, but I still figured I'd ask. Thanks.
  • 04-24-2008 6:32 PM In reply to

    Re: Cant create or write to the Xbox HD

    Here's a freshly created example from the XNA Wiki:

    http://www.xnawiki.com/index.php?title=How_do_I_handle_high_scores%3F

    Hope this helps,

    Chad


    Microsoft XNA Unleashed - 2D, 3D, HLSL, Content Pipeline, XACT, Particle Systems, AI, Physics, Game States, Performance, Garbage Collection and 2 full games!
Page 1 of 1 (11 items) Previous Next