Mobiiliohjelmointi/Mobile programming

 

Exercise 6 – File server & files

 

This exercise focuses on how to use file server and read data from a text file.

Download application:  Animation for SDK 3rd FP1(zip file) that is used as a basis for the exercise. NOTE:  if you are using older Symbian SDK, here is same application : Animation for  SDK 2nd FP 3  

The goal of the exercise is to modify animation application so that amount of animated objects and the coordinates (circle shapes in the picture) are read from a text file. 

settings.txt (UNICODE)
10,10
20,20
25,30
30,40
 
Part 1 - read data from a text file

  1. Create a UNICODE file Settings.txt to the folder "Symbian\8.1\S60_2nd_fp3\Epoc32\winscw\c\Documents\Animation"
  2. Connect file server and open a text file (CAEng::ReadDataFromFile)
    1. Declare following objects: RFs fsSession,
      RFile msgFile, TFileText txtFile
    2. Connect to the file server, leave if fails
    3. Push file server into the cleanup stack
    4. Use: "C:\\Documents\\Animation\\Settings.txt" as a constant literal for the file name
    5. Use BaflUtils::FileExists to check if the file is there
    6. Open the file using RFile::Open, leave if this fails
    7. Push file into cleanup stack
    8. Use TFileText::Set to make it use the RFile just opened
    9. Seek to the beginning of file using  TFileText::Seek
  3. Read lines from file
    1. Read a single line into a TBuf<256> descriptor using TFileText::Read
    2. Use while-loop to read all lines from the file
  4. Parse a single line
    1. Write a new member function void ParseLine(TDes& aLine)
    2. Declare a local variable TLex lexer(aLine);
    3. Use TLex.SkipSpaceAndMark to set the next character position to its exraction mark
    4. Read characters in a  while-loop using TLex.Get until you find a separator (comma)
    5. Unread the last comma using TLex.UnGet
    6. Read the x coordinate using TPtrC TLex.MarkedToken
    7. Skip comma using TLext.SkipAndMark(1);
    8. Read the y coordinate using TLex.Remainder;
  5. Convert string to int and insert coordinates to the array
    1. Convert string to integer using TLex.Val
    2. Append coordinates to the iObjArray using TPoint type.
  6. Close file and file server
      1. Pop and destroy the File from CleanupStack
      2. Pop and destroy the file server from CleanupStack