public override void NotifySelectionChanged(IEntryModel[] appliedModels)
        {
            List <ICommandModel> subItemList = new List <ICommandModel>();

            if (appliedModels.Count() == 1)
            {
                GoogleDriveItemModel model = appliedModels[0] as GoogleDriveItemModel;
                if (model != null && model.Metadata != null && model.Metadata.ExportLinks != null)
                {
                    foreach (var mimeType in model.Metadata.ExportLinks.Keys)
                    {
                        string url = model.Metadata.ExportLinks[mimeType];

                        string ext   = null;
                        var    match = Regex.Match(url, "[&]exportFormat=(?<ext>[\\w]*)$", RegexOptions.IgnoreCase);
                        if (match.Success)
                        {
                            ext = "." + match.Groups["ext"].Value;
                        }
                        else
                        {
                            ext = ShellUtils.MIMEType2Extension(mimeType);
                        }

                        string filter      = String.Format("{0} ({1})|*{1}", mimeType, ext);
                        string defaultName = System.IO.Path.ChangeExtension(appliedModels[0].Name, ext);

                        if (ext != null)
                        {
                            subItemList.Add(
                                new CommandModel(
                                    //SaveFile --> ParseOrCreatePath -> ShowProgress -> Download -> HideProgress
                                    //         --> OK (If cancel)
                                    WPFScriptCommands.SaveFilePicker(WindowManager, Events,
                                                                     _rootModelFunc(), filter, defaultName,
                                                                     (fi) => WPFScriptCommands.ParseOrCreatePath(fi.Profile as IDiskProfile,
                                                                                                                 fi.FileName, false,
                                                                                                                 (m) => WPFScriptCommands.ShowProgress(WindowManager, "Saving",
                                                                                                                                                       WPFScriptCommands.Download(url, m,
                                                                                                                                                                                  (appliedModels[0].Profile as GoogleDriveProfile)
                                                                                                                                                                                  .HttpClientFunc(),
                                                                                                                                                                                  new HideProgress()))),
                                                                     ResultCommand.OK)
                                    )
                            {
                                Header          = String.Format("{0} ({1})", mimeType, ext),
                                IsEnabled       = true,
                                IsVisibleOnMenu = true
                            });
                        }
                    }
                }
            }

            SubCommands    = subItemList;
            this.IsEnabled = subItemList.Count() > 0;
        }
        internal void init(GoogleDriveProfile profile, string path, Google.Apis.Drive.v2.Data.File f)
        {
            init(profile, path);
            UniqueId         = f.Id;
            this.Metadata    = f;
            this.IsDirectory = f.MimeType.Equals(GoogleMimeTypeManager.FolderMimeType);
            this.Name        = profile.Path.GetFileName(path);

            this.Size         = f.FileSize.HasValue ? f.FileSize.Value : 0;
            this._isRenamable = true;

            this.Description      = f.Description;
            this.ImageUrl         = f.ThumbnailLink;
            this.SourceUrl        = f.DownloadUrl;
            this.SourceExportUrls = f.ExportLinks;

            this.Type = profile.MimeTypeManager.GetExportableMimeTypes(f.MimeType).FirstOrDefault();
            if (!this.IsDirectory && String.IsNullOrEmpty(Profile.Path.GetExtension(this.Name)))
            {
                string extension = profile.MimeTypeManager.GetExtension(this.Type);
                if (!String.IsNullOrEmpty(extension))
                {
                    this.FullPath += extension;
                    this.Label     = this._name += extension;
                    this.SourceUrl = f.ExportLinks[this.Type];
                }
                else
                {
                    extension = profile.Path.GetExtension(f.OriginalFilename);
                    if (!String.IsNullOrEmpty(extension))
                    {
                        this.FullPath += extension;
                        this.Label     = this._name += extension;
                    }
                }
            }


            this.Size              = f.FileSize.HasValue ? f.FileSize.Value : this.Size;
            this.CreationTimeUtc   = f.CreatedDate.HasValue ? f.CreatedDate.Value.ToUniversalTime() : this.CreationTimeUtc;
            this.LastUpdateTimeUtc = f.LastViewedByMeDate.HasValue ? f.LastViewedByMeDate.Value.ToUniversalTime() : this.LastUpdateTimeUtc;

            if (!this.IsDirectory && System.IO.Path.GetExtension(this.Name) == "" && this.Type != null)
            {
                string extension = ShellUtils.MIMEType2Extension(this.Type);
                if (!String.IsNullOrEmpty(extension))
                {
                    this.Name += extension;
                }
            }
        }
예제 #3
0
        public string GetExtension(string mimeType)
        {
            if (DefaultMimeTypes.ContainsKey(mimeType))
            {
                return(DefaultMimeTypes[mimeType]);
            }

            if (!_mimeLookup.ContainsKey(mimeType))
            {
                _mimeLookup[mimeType] = ShellUtils.MIMEType2Extension(mimeType);
            }

            return(_mimeLookup[mimeType]);
        }