当前位置: 首页>>代码示例>>C#>>正文


C# NSString.StringByDeletingPathExtension方法代码示例

本文整理汇总了C#中NSString.StringByDeletingPathExtension方法的典型用法代码示例。如果您正苦于以下问题:C# NSString.StringByDeletingPathExtension方法的具体用法?C# NSString.StringByDeletingPathExtension怎么用?C# NSString.StringByDeletingPathExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NSString的用法示例。


在下文中一共展示了NSString.StringByDeletingPathExtension方法的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;
        }
开发者ID:smartmobili,项目名称:CocoaBuilder,代码行数:99,代码来源:NSColorList.cs


注:本文中的NSString.StringByDeletingPathExtension方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。