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
+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")]