protected override void BuildXml() { if ( !this.CurrentFolder.CheckAcl( AccessControlRules.FileView ) ) { ConnectorException.Throw( Errors.Unauthorized ); } // Map the virtual path to the local server path. string sServerDir = this.CurrentFolder.ServerPath ; bool bShowThumbs = Request.QueryString["showThumbs"] != null && Request.QueryString["showThumbs"].ToString().Equals( "1" ) ; // Create the "Files" node. XmlNode oFilesNode = XmlUtil.AppendElement( this.ConnectorNode, "Files" ) ; Achilles.Acme.Storage.IO.DirectoryInfo oDir = new Achilles.Acme.Storage.IO.DirectoryInfo( sServerDir ); Achilles.Acme.Storage.IO.FileInfo[] aFiles = oDir.GetFiles(); for ( int i = 0 ; i < aFiles.Length ; i++ ) { Achilles.Acme.Storage.IO.FileInfo oFile = aFiles[i]; string sExtension = System.IO.Path.GetExtension( oFile.Name ) ; if ( Config.Current.CheckIsHiddenFile( oFile.Name ) ) continue; if ( !this.CurrentFolder.ResourceTypeInfo.CheckExtension( sExtension ) ) continue; Decimal iFileSize = Math.Round( (Decimal)oFile.Length / 1024 ) ; if ( iFileSize < 1 && oFile.Length != 0 ) iFileSize = 1 ; // Create the "File" node. XmlNode oFileNode = XmlUtil.AppendElement( oFilesNode, "File" ) ; XmlUtil.SetAttribute( oFileNode, "name", oFile.Name ); XmlUtil.SetAttribute( oFileNode, "date", oFile.LastWriteTime.ToString( "yyyyMMddHHmm" ) ); if ( Config.Current.Thumbnails.Enabled && ( Config.Current.Thumbnails.DirectAccess || bShowThumbs ) && ImageTools.IsImageExtension( sExtension.TrimStart( '.' ) ) ) { bool bFileExists = false; try { bFileExists = Achilles.Acme.Storage.IO.File.Exists(System.IO.Path.Combine(this.CurrentFolder.ThumbsServerPath, oFile.Name)); } catch {} if ( bFileExists ) XmlUtil.SetAttribute( oFileNode, "thumb", oFile.Name ) ; else if ( bShowThumbs ) XmlUtil.SetAttribute( oFileNode, "thumb", "?" + oFile.Name ) ; } XmlUtil.SetAttribute( oFileNode, "size", iFileSize.ToString( CultureInfo.InvariantCulture ) ); } }
protected override void BuildXml() { if ( !this.CurrentFolder.CheckAcl( AccessControlRules.FolderView ) ) { ConnectorException.Throw( Errors.Unauthorized ); } // Map the virtual path to the local server path. string sServerDir = this.CurrentFolder.ServerPath; Achilles.Acme.Storage.IO.DirectoryInfo oDir = new Achilles.Acme.Storage.IO.DirectoryInfo( sServerDir ); if ( !oDir.Exists ) { ConnectorException.Throw( Errors.FolderNotFound ); return; } // Create the "Folders" node. XmlNode oFoldersNode = XmlUtil.AppendElement( this.ConnectorNode, "Folders" ); Achilles.Acme.Storage.IO.DirectoryInfo[] aSubDirs = oDir.GetDirectories(); for ( int i = 0 ; i < aSubDirs.Length ; i++ ) { string sSubDirName = aSubDirs[ i ].Name; if ( Config.Current.CheckIsHiddenFolder( sSubDirName ) ) continue; int aclMask = Config.Current.AccessControl.GetComputedMask( this.CurrentFolder.ResourceTypeName, this.CurrentFolder.ClientPath + sSubDirName + "/" ); if ( ( aclMask & (int)AccessControlRules.FolderView ) != (int)AccessControlRules.FolderView ) continue; // Create the "Folders" node. XmlNode oFolderNode = XmlUtil.AppendElement( oFoldersNode, "Folder" ); XmlUtil.SetAttribute( oFolderNode, "name", sSubDirName ); try { XmlUtil.SetAttribute( oFolderNode, "hasChildren", aSubDirs[ i ].GetDirectories().Length > 0 ? "true" : "false" ); } catch { // It was not possible to verify if it has children. Assume "yes". XmlUtil.SetAttribute( oFolderNode, "hasChildren", "true" ); } XmlUtil.SetAttribute( oFolderNode, "acl", aclMask.ToString() ); } }
/// <summary> /// This method should provide safe substitude for Directory.CreateDirectory(). /// </summary> /// <param name="path">The directory path to be created.</param> /// <returns>A <see cref="System.IO.DirectoryInfo"/> object for the created directory.</returns> /// <remarks> /// <para> /// This method creates all the directory structure if needed. /// </para> /// <para> /// The System.IO.Directory.CreateDirectory() method has a bug that gives an /// error when trying to create a directory and the user has no rights defined /// in one of its parent directories. The CreateDirectory() should be a good /// replacement to solve this problem. /// </para> /// </remarks> public static Achilles.Acme.Storage.IO.DirectoryInfo CreateDirectory( string path ) { // Create the directory info object for that dir (normalized to its absolute representation). Achilles.Acme.Storage.IO.DirectoryInfo oDir = new Achilles.Acme.Storage.IO.DirectoryInfo( Path.GetFullPath( path ) ); try { // Try to create the directory by using standard .Net features. (#415) if ( !oDir.Exists ) oDir.Create(); return oDir; } catch { // TJT: Review this code CreateDirectoryUsingDll( oDir ); return new Achilles.Acme.Storage.IO.DirectoryInfo( path ); } }
protected override void BuildXml() { if ( Request.Form["CKFinderCommand"] != "true" ) { ConnectorException.Throw( Errors.InvalidRequest ); } if ( !this.CurrentFolder.CheckAcl( AccessControlRules.FolderRename ) ) { ConnectorException.Throw( Errors.Unauthorized ); } // The root folder cannot be deleted. if ( this.CurrentFolder.ClientPath == "/" ) { ConnectorException.Throw( Errors.InvalidRequest ); return; } string newFileName = Request[ "NewFolderName" ]; if ( !Connector.CheckFolderName( newFileName ) || Config.Current.CheckIsHiddenFolder( newFileName ) ) { ConnectorException.Throw( Errors.InvalidName ); return; } // Get the current folder. Achilles.Acme.Storage.IO.DirectoryInfo oDir = new Achilles.Acme.Storage.IO.DirectoryInfo( this.CurrentFolder.ServerPath ); bool bMoved = false; try { if ( !oDir.Exists ) ConnectorException.Throw( Errors.InvalidRequest ); else { // Build the new folder path. string newFolderPath = System.IO.Path.Combine( oDir.Parent.FullName, newFileName ); if ( Achilles.Acme.Storage.IO.Directory.Exists( newFolderPath ) || Achilles.Acme.Storage.IO.File.Exists( newFolderPath ) ) ConnectorException.Throw( Errors.AlreadyExist ); oDir.MoveTo( newFolderPath ); bMoved = true; } } catch ( System.UnauthorizedAccessException ) { ConnectorException.Throw( Errors.AccessDenied ); } catch ( System.Security.SecurityException ) { ConnectorException.Throw( Errors.AccessDenied ); } catch ( System.ArgumentException ) { ConnectorException.Throw( Errors.InvalidName ); } catch ( System.NotSupportedException ) { ConnectorException.Throw( Errors.InvalidName ); } catch ( System.IO.PathTooLongException ) { ConnectorException.Throw( Errors.InvalidName ); } catch ( System.IO.IOException ) { ConnectorException.Throw( Errors.Unknown ); } catch ( ConnectorException connectorException ) { throw connectorException; } catch { #if DEBUG throw; #else ConnectorException.Throw( Errors.Unknown ); #endif } if ( bMoved ) { try { // Get the thumbnails folder. Achilles.Acme.Storage.IO.DirectoryInfo oThumbsDir = new Achilles.Acme.Storage.IO.DirectoryInfo( this.CurrentFolder.ThumbsServerPath ); // Build the new folder path. string newThumbsFolderPath = System.IO.Path.Combine( oThumbsDir.Parent.FullName, newFileName ); if ( Achilles.Acme.Storage.IO.Directory.Exists( newThumbsFolderPath ) ) { Achilles.Acme.Storage.IO.File.Delete( this.CurrentFolder.ThumbsServerPath ); } else { try { oThumbsDir.MoveTo( newThumbsFolderPath ); } catch { Achilles.Acme.Storage.IO.File.Delete( this.CurrentFolder.ThumbsServerPath ); } } } catch { /* No errors if we are not able to delete the thumb. */ } string newFolderPath = Regex.Replace( this.CurrentFolder.ClientPath, "[^/]+/?$", newFileName ) + "/"; string newFolderUrl = this.CurrentFolder.ResourceTypeInfo.Url + newFolderPath.TrimStart( '/' ); XmlNode oRenamedNode = XmlUtil.AppendElement( this.ConnectorNode, "RenamedFolder" ); XmlUtil.SetAttribute( oRenamedNode, "newName", newFileName ); XmlUtil.SetAttribute( oRenamedNode, "newPath", newFolderPath ); XmlUtil.SetAttribute( oRenamedNode, "newUrl", newFolderUrl ); } }