125 lines
3.2 KiB
C#
125 lines
3.2 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Windows;
|
|
using FileSystemApi;
|
|
using Microsoft.Phone.Controls;
|
|
using Directory = FileSystemApi.Directory;
|
|
using File = FileSystemApi.File;
|
|
using FileAccess = FileSystemApi.FileAccess;
|
|
using FileShare = FileSystemApi.FileShare;
|
|
using System.Collections.Generic;
|
|
|
|
namespace PhoneNetworkingSample
|
|
{
|
|
public partial class MainPage : PhoneApplicationPage
|
|
{
|
|
// Constructor
|
|
public MainPage()
|
|
{
|
|
InitializeComponent();
|
|
Loaded += new RoutedEventHandler(MainPage_Loaded);
|
|
}
|
|
|
|
string folder;
|
|
|
|
void MainPage_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
folder = "\\Windows\\";
|
|
|
|
refreshContents();
|
|
}
|
|
|
|
private void open(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
|
|
{
|
|
if (fileList.SelectedItem == null)
|
|
return;
|
|
|
|
object selectedObj = fileList.SelectedItem;
|
|
|
|
if (selectedObj.GetType() == typeof(DirectoryData))
|
|
{
|
|
folder += ((DirectoryData)selectedObj).Name + "\\";
|
|
|
|
refreshContents();
|
|
}
|
|
|
|
else if (selectedObj.GetType() == typeof(FileData))
|
|
{
|
|
NavigationService.Navigate(new Uri("/TextDisplay.xaml?path=" + Uri.EscapeDataString(((FileData)selectedObj).FullName), UriKind.Relative));
|
|
}
|
|
|
|
else if (selectedObj as string == "[..]")
|
|
{
|
|
folder = folder.Substring(0, folder.LastIndexOf('\\', folder.Length - 2) + 1);
|
|
|
|
refreshContents();
|
|
}
|
|
}
|
|
|
|
private void refreshContents()
|
|
{
|
|
fileList.Items.Clear();
|
|
|
|
fileList.Items.Add("[..]");
|
|
|
|
foreach (string dir in Directory.GetDirectories(folder, "*"))
|
|
{
|
|
fileList.Items.Add(new DirectoryData(folder + dir));
|
|
}
|
|
|
|
foreach (string dir in Directory.GetFiles(folder, "*"))
|
|
{
|
|
fileList.Items.Add(new FileData(folder + dir));
|
|
}
|
|
}
|
|
}
|
|
|
|
struct DirectoryData
|
|
{
|
|
public DirectoryData(string fullname) : this()
|
|
{
|
|
FullName = fullname;
|
|
}
|
|
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
string[] parts = FullName.Split('\\');
|
|
return parts[parts.Length - 1];
|
|
}
|
|
}
|
|
public string FullName { get; private set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
return "[" + Name + "]";
|
|
}
|
|
}
|
|
|
|
struct FileData
|
|
{
|
|
public FileData(string fullname) : this()
|
|
{
|
|
FullName = fullname;
|
|
}
|
|
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
string[] parts = FullName.Split('\\');
|
|
return parts[parts.Length - 1];
|
|
}
|
|
}
|
|
public string FullName { get; private set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
return Name;
|
|
}
|
|
}
|
|
} |