Back to index

lightning-sunbird  0.9+nobinonly
FileLocator.cs
Go to the documentation of this file.
00001 /* -*- Mode: C#; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Manticore.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Silverstone Interactive.
00020  * Portions created by the Initial Developer are Copyright (C) 2001
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Ben Goodger <ben@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 namespace Silverstone.Manticore.Core
00041 {
00042   using System;
00043   using System.Runtime.InteropServices;
00044   using System.Text;
00045   using System.Windows.Forms;
00046 
00050   public class FileLocator
00051   {
00052     [DllImport("shfolder.dll")]
00053     static extern int SHGetFolderPath(int aOwningWnd, int nFolder, int aToken, int aFlags, StringBuilder buffer);
00054 
00059     public enum SpecialFolders : uint
00060     {
00061       ssfDESKTOP = 0,
00062       ssfPROGRAMS = 0x2,
00063       ssfCONTROLS = 0x3,
00064       ssfPRINTERS = 0x4,
00065       ssfPERSONAL = 0x5,
00066       ssfFAVORITES = 0x6,
00067       ssfSTARTUP = 0x7,
00068       ssfRECENT = 0x8,
00069       ssfSENDTO = 0x9,
00070       ssfBITBUCKET = 0xa,
00071       ssfSTARTMENU = 0xb,
00072       ssfDESKTOPDIRECTORY = 0x10,
00073       ssfDRIVES = 0x11,
00074       ssfNETWORK = 0x12,
00075       ssfNETHOOD = 0x13,
00076       ssfFONTS = 0x14,
00077       ssfTEMPLATES = 0x15,
00078       ssfCOMMONSTARTMENU = 0x16,
00079       ssfCOMMONPROGRAMS = 0x17,
00080       ssfCOMMONSTARTUP = 0x18,
00081       ssfCOMMONDESKTOPDIR = 0x19,
00082       ssfAPPDATA = 0x1a,
00083       ssfPRINTHOOD = 0x1b,
00084       ssfLOCALAPPDATA = 0x1c,
00085       ssfALTSTARTUP = 0x1d,
00086       ssfCOMMONALTSTARTUP = 0x1e,
00087       ssfCOMMONFAVORITES = 0x1f,
00088       ssfINTERNETCACHE = 0x20,
00089       ssfCOOKIES = 0x21,
00090       ssfHISTORY = 0x22,
00091       ssfCOMMONAPPDATA = 0x23,
00092       ssfWINDOWS = 0x24,
00093       ssfSYSTEM = 0x25,
00094       ssfPROGRAMFILES = 0x26,
00095       ssfMYPICTURES = 0x27,
00096       ssfPROFILE = 0x28
00097     }
00098 
00099     public static String GetFolderPath(SpecialFolders aFolder)
00100     {
00101       StringBuilder builder = new StringBuilder(256);
00102       SHGetFolderPath(0, (int) aFolder, 0, 0, builder);
00103       return builder.ToString();
00104     }
00105 
00106     public static String GetManticorePath(String aPath)
00107     {
00108       String path = "";
00109       String appData = "";
00110       switch (aPath) 
00111       {
00112         case "AppData":
00113           path = FileLocator.GetFolderPath(FileLocator.SpecialFolders.ssfAPPDATA);
00114           path += @"\Manticore\";
00115           break;
00116         case "UserPrefs":
00117           appData = FileLocator.GetManticorePath("AppData");
00118           path += appData + @"user-prefs.xml";
00119           break;
00120         case "LocalBookmarks":
00121           appData = FileLocator.GetManticorePath("AppData");
00122           if (appData != "")
00123             path += appData + @"bookmarks.xml";
00124           break;
00125         case "Application":
00126           path = Application.ExecutablePath;
00127           int lastSlash = path.LastIndexOf(@"\");
00128           path = path.Substring(0, lastSlash + 1);
00129           break;
00130       }
00131       return path;
00132     }
00133   }
00134 }