Exemplo n.º 1
0
        static Track GetTrack(ref byte[] arrayToParse, ref LocFile01.Track[] tracks)
        {
            Track track = new Track();
            int cursor = 0;
            int cursor1 = 0;
            // Want a searchable string in which we look for data.
            string parseMe = Encoding.UTF8.GetString(arrayToParse, 0, arrayToParse.Length);

            // 0xFF 52/R 21/! 0D seems to be identifier.
            cursor = parseMe.IndexOf("R!") + 3;
            // Name on GPS is terminated by 0x26/&.
            cursor1 = parseMe.IndexOf("&");
            track.NameOnGps = parseMe.Substring(cursor, cursor1 - cursor);
            cursor1++;
            arrayToParse = Extensions.Right(arrayToParse, cursor1, arrayToParse.Length - cursor1);
            parseMe = Encoding.UTF8.GetString(arrayToParse, 0, arrayToParse.Length);
            cursor = 0;
            // Label on map seems to be terminated by 0x00.
            while (arrayToParse[cursor] != 0x0)
            {
                track.LabelOnMap = track.LabelOnMap + (char)arrayToParse[cursor];
                cursor++;
            }
            cursor++;
            arrayToParse = Extensions.Right(arrayToParse, cursor1, arrayToParse.Length - cursor1);
            // Get rid of eight bytes we don't know what to do with.
            arrayToParse = Extensions.Right(arrayToParse, 8, arrayToParse.Length - 8);
            parseMe = Encoding.UTF8.GetString(arrayToParse, 0, arrayToParse.Length);
            cursor = 0;
            GetTrackPoints(ref arrayToParse, ref track);
            return track;
        }
 private async void bOpenFileDialog_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         // Let user choose a file.
         var picker = new Windows.Storage.Pickers.FileOpenPicker();
         picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.List;
         picker.SuggestedStartLocation =
             Windows.Storage.Pickers.PickerLocationId.Desktop;
         // We only want to look for files with .loc extension.
         picker.FileTypeFilter.Add(".loc");
         // Your turn, user...
         Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();
         if (file != null)
         {
             // Open the file.
             var stream = await file.OpenStreamForReadAsync();
             // Application now has read/write access to the picked file.
             // Stuff the whole file into a byte array.
             var _ContentArray = new byte[(int)stream.Length];
             stream.Read(_ContentArray, 0, (int)stream.Length);
             // Instantiate a LocFile01 object, feeding it the array so 
             // created.
             LocFile01 _LocFile = new LocFile01(_ContentArray);
             // Display information extracted by instantiation of object.
             openedFile.Text = 
                 "Opened file: " + file.Name + "\n" + 
                 "Header: " + _LocFile.Header + "\n" +
                 "Waypoints:" + "\n" +
                     "Name on GPS\t" + 
                     "Label on map\t" + 
                     "Latitude\t" + 
                     "Longitude\t\n";
             foreach(LocFile01.Waypoint w in _LocFile.Waypoints)
             {
                 openedFile.Text = openedFile.Text + 
                     w.NameOnGPS  + "\t" + 
                     w.LabelOnMap + "\t" + 
                     w.Latitude   + "\t" + 
                     w.Longitude  + "\n";
             }
             int foo = _LocFile.Tracks.Count;
             if(_LocFile.Tracks.Count > 0)
             {
                 openedFile.Text = openedFile.Text +
                     "Track(s):" + "\n";
                 foreach(var t in _LocFile.Tracks)
                 {
                     openedFile.Text = openedFile.Text +
                         "Trackpoints in track " + t.LabelOnMap + ":" + "\n" +
                         "Latitude\t" +
                         "Longitude\t\n";
                     //foreach (var tp in t)
                     //{
                     //    openedFile.Text = openedFile.Text +
                     //}
                 }
             }
         }
         else
         {
             openedFile.Text = "File selection cancelled.";
         }
     }
     catch(InvalidOperationException ioe)
     {
         openedFile.Text = "Exception encountered in .LOC file.\n" +
                           ioe.Message;
     }
     catch (Exception exc)
     {
         openedFile.Text = "Exception: " + exc.Message;
     }
     finally { }
 }