本文整理汇总了C#中System.IO.File.TryOpen方法的典型用法代码示例。如果您正苦于以下问题:C# File.TryOpen方法的具体用法?C# File.TryOpen怎么用?C# File.TryOpen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.File
的用法示例。
在下文中一共展示了File.TryOpen方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public void Init(Ioctls ioctls, Core core, Runtime runtime)
{
IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
MoSync.SystemPropertyManager.RegisterSystemPropertyProvider("mosync.path.local",
delegate(String key)
{
// The isolated storage becomes the "root"
return "/";
}
);
ioctls.maFileOpen = delegate(int _path, int _mode)
{
String path = core.GetDataMemory().ReadStringAtAddress(_path);
path = ConvertPath(path);
File file = null;
FileAccess access = 0;
if (_mode == MoSync.Constants.MA_ACCESS_READ)
{
access = FileAccess.Read;
}
else if (_mode == MoSync.Constants.MA_ACCESS_READ_WRITE)
{
access = FileAccess.ReadWrite;
}
else
{
throw new Exception("Invalid file access mode");
}
file = new File(path, access);
if (file.IsDirectory)
{
if (isolatedStorage.FileExists(path))
return MoSync.Constants.MA_FERR_WRONG_TYPE;
}
else
{
if (isolatedStorage.DirectoryExists(path))
return MoSync.Constants.MA_FERR_WRONG_TYPE;
try
{
file.TryOpen();
}
catch (IsolatedStorageException e)
{
MoSync.Util.Log(e);
return MoSync.Constants.MA_FERR_GENERIC;
}
}
mFileHandles.Add(mNextFileHandle, file);
return mNextFileHandle++;
};
ioctls.maFileClose = delegate(int _file)
{
File file = mFileHandles[_file];
file.Close();
mFileHandles.Remove(_file);
return 0;
};
ioctls.maFileRead = delegate(int _file, int _dst, int _len)
{
File file = mFileHandles[_file];
if (file.IsDirectory)
return MoSync.Constants.MA_FERR_WRONG_TYPE;
IsolatedStorageFileStream fileStream = file.FileStream;
if (fileStream == null)
return MoSync.Constants.MA_FERR_GENERIC;
core.GetDataMemory().WriteFromStream(_dst, fileStream, _len);
return 0;
};
ioctls.maFileReadToData = delegate(int _file, int _data, int _offset, int _len)
{
File file = mFileHandles[_file];
if (file.IsDirectory)
return MoSync.Constants.MA_FERR_WRONG_TYPE;
IsolatedStorageFileStream fileStream = file.FileStream;
if (fileStream == null)
return MoSync.Constants.MA_FERR_GENERIC;
Resource dataRes = runtime.GetResource(MoSync.Constants.RT_BINARY, _data);
//Memory data = (Memory)dataRes.GetInternalObject();
Stream data = (Stream)dataRes.GetInternalObject();
MoSync.Util.CopySeekableStreams(fileStream, (int)fileStream.Position,
data, _offset, _len);
//data.WriteFromStream(_offset, fileStream, _len);
return 0;
};
ioctls.maFileWriteFromData = delegate(int _file, int _data, int _offset, int _len)
{
File file = mFileHandles[_file];
if (file.IsDirectory)
//.........这里部分代码省略.........