Util.cs :  » Content-Management-Systems-CMS » JMDCMS » FredCK » FCKeditorV2 » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Content Management Systems CMS » JMDCMS 
JMDCMS » FredCK » FCKeditorV2 » Util.cs
/*
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2005 Frederico Caldeira Knabben
 * 
 * Licensed under the terms of the GNU Lesser General Public License:
 *     http://www.opensource.org/licenses/lgpl-license.php
 * 
 * For further information visit:
 *     http://www.fckeditor.net/
 * 
 * "Support Open Source software. What about a donation today?"
 * 
 * File Name: Util.cs
 *   Useful tools.
 * 
 * File Authors:
 *     Frederico Caldeira Knabben (fredck@fckeditor.net)
 */

using System;
using System.Runtime.InteropServices;
using System.IO;
using System.Collections;

namespace FredCK.FCKeditorV2{
  public sealed class Util
  {
    // The "_mkdir" function is used by the "CreateDirectory" method.
    [DllImport("msvcrt.dll", SetLastError=true)]
    private static extern int _mkdir(string path) ;

    private Util()
    {}

    /// <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 DirectoryInfo CreateDirectory( string path )
    {
      ArrayList oDirsToCreate = new ArrayList() ;

      // Create the directory info object for that dir (normalized to its absolute representation).
      DirectoryInfo oDir = new DirectoryInfo( Path.GetFullPath( path ) ) ;

      // Check the entire path structure to find directories that must be created.
      while ( oDir != null && !oDir.Exists )
      {
        oDirsToCreate.Add( oDir.FullName ) ;
        oDir = oDir.Parent ;
      }

      // "oDir == null" means that the check arrives in the root and it doesn't exist too.
      if ( oDir == null )
        throw( new System.IO.DirectoryNotFoundException( "Directory \"" + oDirsToCreate[ oDirsToCreate.Count-1 ] + "\" not found." ) ) ;

      // Create all directories that must be created (from bottom to top).
      for( int i = oDirsToCreate.Count - 1 ; i >= 0 ; i-- )
      {
        string sPath = (string)oDirsToCreate[i] ;
        int iReturn = _mkdir( sPath ) ;

        if ( iReturn != 0 )
          throw new ApplicationException("Error calling [msvcrt.dll]:_wmkdir(" + sPath + "), error code: " + iReturn );
      }

      return new DirectoryInfo( path ) ;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.