a lot of old projects

This commit is contained in:
2017-03-09 21:08:25 +00:00
parent 6e455885b6
commit 19a97c796f
142 changed files with 4676 additions and 0 deletions
Binary file not shown.
+99
View File
@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace FileSystemApi
{
public class Directory
{
public static string[] GetFiles(string path, string searchString)
{
var fileList = new List<string>();
IntPtr hFind = IntPtr.Zero;
WIN32_FIND_DATA findData;
string fullPathQuery = System.IO.Path.Combine(path, searchString);
int ret = FileSystem.FindFirstFile(fullPathQuery, out findData, out hFind);
if(ret == 0 || hFind == new IntPtr(-1))
{
return fileList.ToArray();
}
if( (findData.dwFileAttributes & FileAttributes.Directory) != FileAttributes.Directory )
{
fileList.Add(findData.cFileName);
}
while(true)
{
ret = FileSystem.FindNextFile(hFind, out findData);
if(ret == 0)
{
break;
}
if ((findData.dwFileAttributes & FileAttributes.Directory) != FileAttributes.Directory)
{
fileList.Add(findData.cFileName);
}
}
FileSystem.FindClose(hFind);
return fileList.ToArray();
}
public static string[] GetDirectories(string path, string searchString)
{
var fileList = new List<string>();
IntPtr hFind = IntPtr.Zero;
WIN32_FIND_DATA findData;
string fullPathQuery = System.IO.Path.Combine(path, searchString);
int ret = FileSystem.FindFirstFile(fullPathQuery, out findData, out hFind);
if (ret == 0 || hFind == new IntPtr(-1))
{
int err = Microsoft.Phone.InteropServices.Marshal.GetLastWin32Error();
return fileList.ToArray();
}
if ((findData.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
{
fileList.Add(findData.cFileName);
}
while (true)
{
ret = FileSystem.FindNextFile(hFind, out findData);
if (ret == 0)
{
break;
}
if ((findData.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
{
fileList.Add(findData.cFileName);
}
}
FileSystem.FindClose(hFind);
return fileList.ToArray();
}
}
}
+106
View File
@@ -0,0 +1,106 @@
using System;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
namespace FileSystemApi
{
public class File
{
private IntPtr m_hFile;
private FileAccess m_fileAccess;
private long m_length;
internal File()
{
}
internal int Read(byte[] buffer, int offset, int count)
{
int bytesRead = 0;
int ret = FileSystem.ReadFile(Handle, buffer, count, offset, out bytesRead);
return bytesRead;
}
internal long Seek(long offset, SeekOrigin origin)
{
MoveMethod method;
switch (origin)
{
case SeekOrigin.Begin:
method = MoveMethod.Begin;
break;
case SeekOrigin.Current:
method = MoveMethod.Current;
break;
case SeekOrigin.End:
method = MoveMethod.End;
break;
default:
throw new ArgumentOutOfRangeException("origin");
}
return FileSystem.SeekFile(Handle, (int)offset, method);
}
internal void Close()
{
FileSystem.CloseFile(m_hFile);
}
internal FileAccess FileAccess
{
get { return m_fileAccess; }
private set { m_fileAccess = value; }
}
internal long Length
{
get { return m_length; }
private set { m_length = value; }
}
internal long Position
{
get
{
return FileSystem.SeekFile(Handle, 0, MoveMethod.Current);
}
}
internal IntPtr Handle
{
get { return m_hFile; }
private set { m_hFile = value; }
}
public static FileStream Open(string lpFilename,
FileAccess dwDesiredAccess,
FileShare dwShareMode,
CreationDisposition dwCreationDisposition)
{
var dwFlagsAndAttributes = FileAttributes.Normal;
var file = new File();
file.FileAccess = dwDesiredAccess;
int ret = FileSystem.OpenFile(lpFilename,
dwDesiredAccess,
dwShareMode,
dwCreationDisposition,
dwFlagsAndAttributes,
out file.m_hFile);
if(file.Handle == IntPtr.Zero)
throw new Exception("Could not open file");
file.m_length = FileSystem.GetFileSize(file.Handle);
return new FileStream(file);
}
}
}
+78
View File
@@ -0,0 +1,78 @@
using System;
using System.IO;
namespace FileSystemApi
{
public class FileStream : Stream
{
private File m_file;
internal FileStream(File file)
{
m_file = file;
}
public override bool CanRead
{
get
{
return (m_file.FileAccess & FileAccess.Read) == FileAccess.Read;
}
}
public override bool CanSeek
{
get { return true; }
}
public override bool CanWrite
{
get
{
return (m_file.FileAccess & FileAccess.Write) == FileAccess.Write;
}
}
public override void Flush()
{
throw new NotImplementedException();
}
public override long Length
{
get { return m_file.Length; }
}
public override long Position
{
get { return m_file.Position; }
set { Seek(value, SeekOrigin.Begin); }
}
public override int Read(byte[] buffer, int offset, int count)
{
return m_file.Read(buffer, offset, count);
}
public override long Seek(long offset, SeekOrigin origin)
{
return m_file.Seek(offset, origin);
}
public override void SetLength(long value)
{
throw new NotImplementedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new NotImplementedException();
}
public override void Close()
{
m_file.Close();
base.Close();
}
}
}
+236
View File
@@ -0,0 +1,236 @@
using System;
using System.Net;
using System.Runtime.InteropServices;
using Microsoft.Phone.InteropServices;
namespace FileSystemApi
{
[Flags]
public enum FileAccess : uint
{
/// <summary>
/// Read file access
/// </summary>
Read = 0x80000000,
/// <summary>
/// Write file acecss
/// </summary>
Write = 0x40000000,
/// <summary>
/// Execute file access
/// </summary>
Execute = 0x20000000,
/// <summary>
///
/// </summary>
All = 0x10000000
}
[Flags]
public enum FileShare : uint
{
/// <summary>
///
/// </summary>
None = 0x00000000,
/// <summary>
/// Enables subsequent open operations on an object to request read access.
/// Otherwise, other processes cannot open the object if they request read access.
/// If this flag is not specified, but the object has been opened for read access, the function fails.
/// </summary>
Read = 0x00000001,
/// <summary>
/// Enables subsequent open operations on an object to request write access.
/// Otherwise, other processes cannot open the object if they request write access.
/// If this flag is not specified, but the object has been opened for write access, the function fails.
/// </summary>
Write = 0x00000002,
/// <summary>
/// Enables subsequent open operations on an object to request delete access.
/// Otherwise, other processes cannot open the object if they request delete access.
/// If this flag is not specified, but the object has been opened for delete access, the function fails.
/// </summary>
Delete = 0x00000004
}
public enum CreationDisposition : uint
{
/// <summary>
/// Creates a new file. The function fails if a specified file exists.
/// </summary>
New = 1,
/// <summary>
/// Creates a new file, always.
/// If a file exists, the function overwrites the file, clears the existing attributes, combines the specified file attributes,
/// and flags with FILE_ATTRIBUTE_ARCHIVE, but does not set the security descriptor that the SECURITY_ATTRIBUTES structure specifies.
/// </summary>
CreateAlways = 2,
/// <summary>
/// Opens a file. The function fails if the file does not exist.
/// </summary>
OpenExisting = 3,
/// <summary>
/// Opens a file, always.
/// If a file does not exist, the function creates a file as if dwCreationDisposition is CREATE_NEW.
/// </summary>
OpenAlways = 4,
/// <summary>
/// Opens a file and truncates it so that its size is 0 (zero) bytes. The function fails if the file does not exist.
/// The calling process must open the file with the GENERIC_WRITE access right.
/// </summary>
TruncateExisting = 5
}
[Flags]
public enum FileAttributes : uint
{
Readonly = 0x00000001,
Hidden = 0x00000002,
System = 0x00000004,
Directory = 0x00000010,
Archive = 0x00000020,
Device = 0x00000040,
Normal = 0x00000080,
Temporary = 0x00000100,
SparseFile = 0x00000200,
ReparsePoint = 0x00000400,
Compressed = 0x00000800,
Offline = 0x00001000,
NotContentIndexed = 0x00002000,
Encrypted = 0x00004000,
WriteThrough = 0x80000000,
Overlapped = 0x40000000,
NoBuffering = 0x20000000,
RandomAccess = 0x10000000,
SequentialScan = 0x08000000,
DeleteOnClose = 0x04000000,
BackupSemantics = 0x02000000,
PosixSemantics = 0x01000000,
OpenReparsePoint = 0x00200000,
OpenNoRecall = 0x00100000,
FirstPipeInstance = 0x00080000
}
internal enum MoveMethod : uint
{
Begin = 0,
Current = 1,
End = 2
}
[StructLayout(LayoutKind.Explicit, Size = 8)]
internal struct LARGE_INTEGER
{
[FieldOffset(0)]
public Int64 QuadPart;
[FieldOffset(0)]
public Int32 LowPart;
[FieldOffset(4)]
public Int32 HighPart;
}
internal static class FileSystem
{
private static IFileSystemIO m_fileSystemIo;
private const int INVALID_FILE_SIZE = unchecked((int) 0xffffffff);
private const int INVALID_SET_FILE_POINTER = -1;
private const int ERROR_ACCESS_DENIED = unchecked((int)0x80000005);
static FileSystem()
{
ComBridge.RegisterComDll("FileSystem.dll", new Guid("F0D5AFD8-DA24-4e85-9335-BEBCADE5B92A"));
m_fileSystemIo = new FileSystemClass() as IFileSystemIO;
}
public static int OpenFile(string lpFilename, FileAccess dwDesiredAccess, FileShare dwShareMode, CreationDisposition dwCreationDisposition, FileAttributes dwFlagsAndAttributes, out IntPtr hFile)
{
int ret = m_fileSystemIo.OpenFile(lpFilename, (int)dwDesiredAccess, (int)dwShareMode, (int)dwCreationDisposition, (int)dwFlagsAndAttributes, out hFile);
return ret;
}
public static int ReadFile(IntPtr hfile, byte[] buffer, int nNumberOfBytesToRead, int offset, out int lpNumberOfBytesRead)
{
var bufferHandle = Microsoft.Phone.InteropServices.GCHandle.Alloc(buffer, GCHandleType.Pinned);
int ret = m_fileSystemIo.ReadFile(hfile, new IntPtr(bufferHandle.AddrOfPinnedObject().ToInt32() + offset),
nNumberOfBytesToRead,
out lpNumberOfBytesRead);
bufferHandle.Free();
if (ret == 0)
{
int err = Microsoft.Phone.InteropServices.Marshal.GetLastWin32Error();
if (err == ERROR_ACCESS_DENIED)
{
throw new UnauthorizedAccessException("Access denied");
}
}
return ret;
}
public static int CloseFile(IntPtr hFile)
{
return m_fileSystemIo.CloseFile(hFile);
}
public static int SeekFile(IntPtr hFile, long lDistanceToMove, MoveMethod dwMoveMethod)
{
var li = new LARGE_INTEGER();
li.QuadPart = lDistanceToMove;
var ret = m_fileSystemIo.SeekFile(hFile, li.LowPart, ref li.HighPart, (int) dwMoveMethod);
if(ret == INVALID_SET_FILE_POINTER)
throw new Exception("Invalid seek");
return ret;
}
public static long GetFileSize(IntPtr hFile)
{
var li = new LARGE_INTEGER();
li.LowPart = m_fileSystemIo.GetFileSize(hFile, out li.HighPart);
if(li.LowPart == INVALID_FILE_SIZE)
throw new Exception("Invalid file size");
return li.QuadPart;
}
public static int CopyFile(string sourceFilename, string destinationFilename, bool failIfExists)
{
int ret = m_fileSystemIo.CopyFile(sourceFilename, destinationFilename, failIfExists);
if (ret == 0)
{
int err = Microsoft.Phone.InteropServices.Marshal.GetLastWin32Error();
if (err == ERROR_ACCESS_DENIED)
{
throw new UnauthorizedAccessException("Access denied");
}
}
return ret;
}
public static int FindFirstFile(string lpFileName, out WIN32_FIND_DATA lpFindFileData, out IntPtr hFind)
{
return m_fileSystemIo.FindFirstFile(lpFileName, out lpFindFileData, out hFind);
}
public static int FindNextFile(IntPtr hFind, out WIN32_FIND_DATA lpFindFileData)
{
return m_fileSystemIo.FindNextFile(hFind, out lpFindFileData);
}
public static int FindClose(IntPtr hFind)
{
return m_fileSystemIo.FindClose(hFind);
}
}
}
+69
View File
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.20506</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{863BF1CD-9532-4FF5-A022-11DF7D76B1C4}</ProjectGuid>
<ProjectTypeGuids>{C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FileSystemApi</RootNamespace>
<AssemblyName>FileSystemApi</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
<TargetFrameworkProfile>WindowsPhone</TargetFrameworkProfile>
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
<SilverlightApplication>false</SilverlightApplication>
<ValidateXaml>true</ValidateXaml>
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Bin\Debug</OutputPath>
<DefineConstants>DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>Bin\Release</OutputPath>
<DefineConstants>TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Phone.InteropServices, Version=7.0.0.0, Culture=neutral, PublicKeyToken=24eec0d8c86cda1e, processorArchitecture=MSIL" />
<Reference Include="System.Windows" />
<Reference Include="system" />
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
<Reference Include="System.Net" />
</ItemGroup>
<ItemGroup>
<Compile Include="Directory.cs" />
<Compile Include="File.cs" />
<Compile Include="FileStream.cs" />
<Compile Include="FileSystem.cs" />
<Compile Include="Interop.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.$(TargetFrameworkProfile).Overrides.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.CSharp.targets" />
<ProjectExtensions />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<FullDeploy>true</FullDeploy>
</PropertyGroup>
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{C089C8C0-30E0-4E22-80C0-CE093F111A43}">
<SilverlightMobileCSProjectFlavor>
<FullDeploy>True</FullDeploy>
</SilverlightMobileCSProjectFlavor>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
</Project>
+74
View File
@@ -0,0 +1,74 @@
using System;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace FileSystemApi
{
[ComImport, Guid("F0D5AFD8-DA24-4e85-9335-BEBCADE5B92A"),
ClassInterface(ClassInterfaceType.None)]
internal class FileSystemClass
{
}
[StructLayout(LayoutKind.Sequential)]
internal struct FILETIME
{
public uint dwLowDateTime;
public uint dwHighDateTime;
};
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct WIN32_FIND_DATA
{
public FileAttributes dwFileAttributes;
public FILETIME ftCreationTime;
public FILETIME ftLastAccessTime;
public FILETIME ftLastWriteTime;
public int nFileSizeHigh;
public int nFileSizeLow;
public int dwReserved0;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string cFileName;
}
[ComImport, Guid("2C49FA3D-C6B7-4168-BE80-D044A9C0D9DD"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IFileSystemIO
{
[PreserveSig]
int OpenFile(string lpFilename, int dwDesiredAccess, int dwShareMode, int dwCreationDisposition, int dwFlagsAndAttributes, out IntPtr hFile);
[PreserveSig]
int ReadFile(IntPtr hfile, IntPtr lpBuffer, int nNumberOfBytesToRead, out int lpNumberOfBytesRead);
[PreserveSig]
int CloseFile(IntPtr hFile);
[PreserveSig]
int SeekFile(IntPtr hFile, int lDistanceToMove, ref int lpDistanceToMoveHigh, int dwMoveMethod);
[PreserveSig]
int GetFileSize(IntPtr hFile, out int lpFileSizeHigh);
[PreserveSig]
int CopyFile(string lpExistingFileName, string lpNewFileName, bool bFailIfExists);
[PreserveSig]
int FindFirstFile(string lpFileName, out WIN32_FIND_DATA lpFindFileData, out IntPtr hFind);
[PreserveSig]
int FindNextFile(IntPtr hFind, out WIN32_FIND_DATA lpFindFileData);
[PreserveSig]
int FindClose(IntPtr hFind);
}
}
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("FileSystemApi")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("FileSystemApi")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a5c8576b-29ec-4b0f-b820-c62aef58ba95")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
+28
View File
@@ -0,0 +1,28 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileSystemSample", "FileSystemSample\FileSystemSample.csproj", "{3DD034FF-996C-4903-AAEC-1336D63E8719}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileSystemApi", "FileSystemApi\FileSystemApi.csproj", "{863BF1CD-9532-4FF5-A022-11DF7D76B1C4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3DD034FF-996C-4903-AAEC-1336D63E8719}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3DD034FF-996C-4903-AAEC-1336D63E8719}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3DD034FF-996C-4903-AAEC-1336D63E8719}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{3DD034FF-996C-4903-AAEC-1336D63E8719}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3DD034FF-996C-4903-AAEC-1336D63E8719}.Release|Any CPU.Build.0 = Release|Any CPU
{3DD034FF-996C-4903-AAEC-1336D63E8719}.Release|Any CPU.Deploy.0 = Release|Any CPU
{863BF1CD-9532-4FF5-A022-11DF7D76B1C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{863BF1CD-9532-4FF5-A022-11DF7D76B1C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{863BF1CD-9532-4FF5-A022-11DF7D76B1C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{863BF1CD-9532-4FF5-A022-11DF7D76B1C4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file not shown.
+19
View File
@@ -0,0 +1,19 @@
<Application
x:Class="PhoneNetworkingSample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">
<!--Application Resources-->
<Application.Resources>
</Application.Resources>
<Application.ApplicationLifetimeObjects>
<!--Required object that handles lifetime events for the application-->
<shell:PhoneApplicationService
Launching="Application_Launching" Closing="Application_Closing"
Activated="Application_Activated" Deactivated="Application_Deactivated"/>
</Application.ApplicationLifetimeObjects>
</Application>
+135
View File
@@ -0,0 +1,135 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
namespace PhoneNetworkingSample
{
public partial class App : Application
{
/// <summary>
/// Provides easy access to the root frame of the Phone Application.
/// </summary>
/// <returns>The root frame of the Phone Application.</returns>
public PhoneApplicationFrame RootFrame { get; private set; }
/// <summary>
/// Constructor for the Application object.
/// </summary>
public App()
{
// Global handler for uncaught exceptions.
UnhandledException += Application_UnhandledException;
// Show graphics profiling information while debugging.
if (System.Diagnostics.Debugger.IsAttached)
{
// Display the current frame rate counters.
Application.Current.Host.Settings.EnableFrameRateCounter = true;
// Show the areas of the app that are being redrawn in each frame.
//Application.Current.Host.Settings.EnableRedrawRegions = true;
// Enable non-production analysis visualization mode,
// which shows areas of a page that are being GPU accelerated with a colored overlay.
//Application.Current.Host.Settings.EnableCacheVisualization = true;
}
// Standard Silverlight initialization
InitializeComponent();
// Phone-specific initialization
InitializePhoneApplication();
}
// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
}
// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
}
// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
}
// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
}
// Code to execute if a navigation fails
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// A navigation has failed; break into the debugger
System.Diagnostics.Debugger.Break();
}
}
// Code to execute on Unhandled Exceptions
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
}
#region Phone application initialization
// Avoid double-initialization
private bool phoneApplicationInitialized = false;
// Do not add any additional code to this method
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
// Create the frame but don't set it as RootVisual yet; this allows the splash
// screen to remain active until the application is ready to render.
RootFrame = new PhoneApplicationFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
// Handle navigation failures
RootFrame.NavigationFailed += RootFrame_NavigationFailed;
// Ensure we don't initialize again
phoneApplicationInitialized = true;
}
// Do not add any additional code to this method
private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
{
// Set the root visual to allow the application to render
if (RootVisual != RootFrame)
RootVisual = RootFrame;
// Remove this handler since it is no longer needed
RootFrame.Navigated -= CompleteInitializePhoneApplication;
}
#endregion
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.20506</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{3DD034FF-996C-4903-AAEC-1336D63E8719}</ProjectGuid>
<ProjectTypeGuids>{C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PhoneNetworkingSample</RootNamespace>
<AssemblyName>PhoneNetworkingSample</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
<TargetFrameworkProfile>WindowsPhone</TargetFrameworkProfile>
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
<SilverlightApplication>true</SilverlightApplication>
<SupportedCultures>
</SupportedCultures>
<XapOutputs>true</XapOutputs>
<GenerateSilverlightManifest>true</GenerateSilverlightManifest>
<XapFilename>PhoneNetworkingSample.xap</XapFilename>
<SilverlightManifestTemplate>Properties\AppManifest.xml</SilverlightManifestTemplate>
<SilverlightAppEntry>PhoneNetworkingSample.App</SilverlightAppEntry>
<ValidateXaml>true</ValidateXaml>
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Bin\Debug</OutputPath>
<DefineConstants>DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>Bin\Release</OutputPath>
<DefineConstants>TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Phone" />
<Reference Include="Microsoft.Phone.Interop" />
<Reference Include="System.Windows" />
<Reference Include="system" />
<Reference Include="System.Core" />
<Reference Include="System.Net" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TextDisplay.xaml.cs">
<DependentUpon>TextDisplay.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</ApplicationDefinition>
<Page Include="MainPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="TextDisplay.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<None Include="Properties\AppManifest.xml" />
<None Include="Properties\WMAppManifest.xml">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="ApplicationIcon.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Background.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="FileSystem.dll" />
<Content Include="SplashScreenImage.jpg" />
<Content Include="WPInteropManifest.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FileSystemApi\FileSystemApi.csproj">
<Project>{863BF1CD-9532-4FF5-A022-11DF7D76B1C4}</Project>
<Name>FileSystemApi</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.$(TargetFrameworkProfile).Overrides.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<ProjectExtensions />
</Project>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<FullDeploy>false</FullDeploy>
</PropertyGroup>
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{C089C8C0-30E0-4E22-80C0-CE093F111A43}">
<SilverlightMobileCSProjectFlavor>
<FullDeploy>False</FullDeploy>
</SilverlightMobileCSProjectFlavor>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
</Project>
+47
View File
@@ -0,0 +1,47 @@
<phone:PhoneApplicationPage
x:Class="PhoneNetworkingSample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="FILE BROWSER" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="browser" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ListBox Name="fileList" SelectionChanged="open" />
</Grid>
</Grid>
<!--Sample code showing usage of ApplicationBar-->
<!--<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="MenuItem 1"/>
<shell:ApplicationBarMenuItem Text="MenuItem 2"/>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>-->
</phone:PhoneApplicationPage>
+125
View File
@@ -0,0 +1,125 @@
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;
}
}
}
@@ -0,0 +1,6 @@
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Deployment.Parts>
</Deployment.Parts>
</Deployment>
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PhoneNetworkingSample")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("PhoneNetworkingSample")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3a5d0377-3f04-49dd-bbe2-987d531b2848")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Deployment xmlns="http://schemas.microsoft.com/windowsphone/2009/deployment" AppPlatformVersion="7.0">
<App xmlns="" ProductID="{BC4F319C-9A9A-DF11-A490-00237DE2DB9E}" Title="File Browser" RuntimeType="Silverlight" Version="1.0.0.0" Genre="apps.normal" Author="author" Description="Sample description" Publisher="Publisher">
<IconPath IsRelative="true" IsResource="false">ApplicationIcon.png</IconPath>
<Capabilities>
<Capability Name="ID_CAP_GAMERSERVICES" />
<Capability Name="ID_CAP_IDENTITY_DEVICE" />
<Capability Name="ID_CAP_IDENTITY_USER" />
<Capability Name="ID_CAP_LOCATION" />
<Capability Name="ID_CAP_MEDIALIB" />
<Capability Name="ID_CAP_MICROPHONE" />
<Capability Name="ID_CAP_NETWORKING" />
<Capability Name="ID_CAP_PHONEDIALER" />
<Capability Name="ID_CAP_PUSH_NOTIFICATION" />
<Capability Name="ID_CAP_SENSORS" />
<Capability Name="ID_CAP_WEBBROWSERCOMPONENT" />
<Capability Name="ID_CAP_IDENTITY_USER" />
<Capability Name="ID_CAP_INTEROPSERVICES" />
</Capabilities>
<Tasks>
<DefaultTask Name="_default" NavigationPage="MainPage.xaml" />
</Tasks>
<Tokens>
<PrimaryToken TokenID="PhoneSampleToken" TaskName="_default">
<TemplateType5>
<BackgroundImageURI IsRelative="true" IsResource="false">Background.png</BackgroundImageURI>
<Count>0</Count>
<Title>File Browser</Title>
</TemplateType5>
</PrimaryToken>
</Tokens>
</App>
</Deployment>
Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

+36
View File
@@ -0,0 +1,36 @@
<phone:PhoneApplicationPage
x:Class="PhoneNetworkingSample.TextDisplay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent" Loaded="loadData">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="FILE BROWSER" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="text reader" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBox HorizontalAlignment="Stretch" Margin="0,32,0,0" Name="displayTxt" Text="TextBox" VerticalAlignment="Stretch" FontSize="20" TextWrapping="Wrap" />
<TextBlock Height="32" HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="displayName" Text="[FILENAME]" VerticalAlignment="Top" />
</Grid>
</Grid>
</phone:PhoneApplicationPage>
+50
View File
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using FileSystemApi;
using StreamReader = System.IO.StreamReader;
namespace PhoneNetworkingSample
{
public partial class TextDisplay : PhoneApplicationPage
{
public string filePath;
public TextDisplay()
{
InitializeComponent();
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if(!NavigationContext.QueryString.TryGetValue("path", out filePath))
{
NavigationService.GoBack();
}
}
private void loadData(object sender, RoutedEventArgs e)
{
filePath = Uri.UnescapeDataString(filePath);
displayName.Text = filePath;
FileStream dataStr = File.Open(filePath, FileAccess.Read, FileShare.Read, CreationDisposition.OpenExisting);
StreamReader dataReader = new StreamReader(dataStr);
displayTxt.Text = dataReader.ReadToEnd();
}
}
}
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<Interop>
</Interop>