コード例 #1
0
ファイル: AssetLut.cs プロジェクト: gl-obsoleted/utouch
        public static AssetDesc CreateDesc(string assetPath)
        {
            string unixStyle = SysUtil.ToUnixPath(SysUtil.TrimHeadTailSeparators(assetPath));
            string filename  = Path.GetFileNameWithoutExtension(unixStyle);
            string ext       = Path.GetExtension(unixStyle);

            if (string.IsNullOrEmpty(filename))
            {
                Logging.Instance.Log("CreateDesc() failed (invalid asset path): {0}.", assetPath);
                return(null);
            }

            string fullpath = Path.Combine(GState.AssetRoot, SysUtil.ToWindowsPath(unixStyle));

            if (!File.Exists(fullpath))
            {
                Logging.Instance.Log("CreateDesc() failed (file not found): {0}.", assetPath);
                return(null);
            }

            string digest = SysUtil.GetFileMD5AsString(fullpath);

            if (string.IsNullOrEmpty(digest))
            {
                Logging.Instance.Log("CreateDesc() failed (md5 calculating failed): {0}.", fullpath);
                return(null);
            }

            AssetType type = AssetType.Unknown;

            if (ext.ToLower() == "png")
            {
                type = AssetType.PNG;
            }

            AssetDesc desc = new AssetDesc();

            desc.LinkTime = DateTime.Now;
            desc.Name     = filename + "_" + desc.LinkTime.ToString("yyyyMMdd_HHmmss");
            desc.Type     = type;
            desc.Path     = unixStyle;
            desc.Digest   = digest;
            return(desc);
        }