本文整理汇总了C#中NSString.StringByDeletingLastPathComponent方法的典型用法代码示例。如果您正苦于以下问题:C# NSString.StringByDeletingLastPathComponent方法的具体用法?C# NSString.StringByDeletingLastPathComponent怎么用?C# NSString.StringByDeletingLastPathComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NSString
的用法示例。
在下文中一共展示了NSString.StringByDeletingLastPathComponent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteToFile
public virtual bool WriteToFile(NSString path)
{
NSFileManager fm = NSFileManager.DefaultManager;
NSString tmpPath = @"";
bool isDir = false;
bool success = false;
bool path_is_standard = true;
/*
* We need to initialize before saving, to avoid the new file being
* counted as a different list thus making us appear twice
*/
NSColorList._LoadAvailableColorLists(null);
if (path == null)
{
NSArray paths;
// FIXME the standard path for saving color lists?
paths = NSSearchPathForDirectoriesInDomains(
NSSearchPathDirectory.NSLibraryDirectory,
NSSearchPathDomainMask.NSUserDomainMask, true);
if (paths.Count == 0)
{
//NSLog (@"Failed to find Library directory for user");
return false; // No directory to save to.
}
path = ((NSString)paths.ObjectAtIndex(0)).StringByAppendingPathComponent(@"Colors");
isDir = true;
}
else
{
fm.FileExistsAtPath(path, ref isDir);
}
if (isDir)
{
_fullFileName = path.StringByAppendingPathComponent(_name).StringByAppendingPathExtension(@"clr");
}
else // it is a file
{
if (path.PathExtension().IsEqualToString(@"clr") == true)
{
_fullFileName = path;
}
else
{
_fullFileName = path.StringByDeletingPathExtension().StringByAppendingPathExtension(@"clr");
}
path = path.StringByDeletingLastPathComponent();
}
// Check if the path is a standard path
if (path.LastPathComponent().IsEqualToString(@"Colors") == false)
{
path_is_standard = false;
}
else
{
tmpPath = path.StringByDeletingLastPathComponent();
if (!NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.NSLibraryDirectory, NSSearchPathDomainMask.NSAllDomainsMask, true).ContainsObject(tmpPath))
{
path_is_standard = false;
}
}
/*
* If path is standard and it does not exist, try to create it.
* System standard paths should always be assumed to exist;
* this will normally then only try to create user paths.
*/
if (path_is_standard && (fm.FileExistsAtPath(path) == false))
{
NSError err = null;
if (fm.CreateDirectoryAtPath(path, true, null, ref err))
{
//NSLog (@"Created standard directory %@", path);
}
else
{
//NSLog (@"Failed attempt to create directory %@", path);
}
}
//success = [NSArchiver archiveRootObject: self toFile: _fullFileName];
if (success && path_is_standard)
{
_colorListLock.Lock();
if (_availableColorLists.ContainsObject(this) == false)
_availableColorLists.AddObject(this);
_colorListLock.Unlock();
return true;
}
return success;
}