Mes documents/Visual Studio 2005/Projects/TES4ModTranslator/TES4ModTranslator/Zip/ZipNameTransform.cs

Go to the documentation of this file.
00001 // ZipNameTransform.cs
00002 //
00003 // Copyright 2005 John Reilly
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 // Linking this library statically or dynamically with other modules is
00020 // making a combined work based on this library.  Thus, the terms and
00021 // conditions of the GNU General Public License cover the whole
00022 // combination.
00023 // 
00024 // As a special exception, the copyright holders of this library give you
00025 // permission to link this library with independent modules to produce an
00026 // executable, regardless of the license terms of these independent
00027 // modules, and to copy and distribute the resulting executable under
00028 // terms of your choice, provided that you also meet, for each linked
00029 // independent module, the terms and conditions of the license of that
00030 // module.  An independent module is a module which is not derived from
00031 // or based on this library.  If you modify this library, you may extend
00032 // this exception to your version of the library, but you are not
00033 // obligated to do so.  If you do not wish to do so, delete this
00034 // exception statement from your version.
00035 
00036 
00037 using System;
00038 using System.IO;
00039 
00040 using ICSharpCode.SharpZipLib.Core;
00041 
00042 namespace ICSharpCode.SharpZipLib.Zip
00043 {
00047         public class ZipNameTransform : INameTransform
00048         {
00053                 public ZipNameTransform()
00054                 {
00055                         relativePath = true;
00056                 }
00057 
00063                 public ZipNameTransform(bool useRelativePaths)
00064                 {
00065                         relativePath = useRelativePaths;
00066                 }
00067 
00074                 public ZipNameTransform(bool useRelativePaths, string trimPrefix)
00075                 {
00076                         this.trimPrefix = trimPrefix;
00077                         relativePath = useRelativePaths;
00078                 }
00079                 
00085                 public string TransformDirectory(string name)
00086                 {
00087                         name = TransformFile(name);
00088                         if (name.Length > 0) {
00089                                 if ( !name.EndsWith("/") ) {
00090                                         name += "/";
00091                                 }
00092                         }
00093                         else {
00094                                 name = "/";
00095                         }
00096                         return name;
00097                 }
00098                 
00104                 public string TransformFile(string name)
00105                 {
00106                         if (name != null) {
00107                                 if ( trimPrefix != null && name.IndexOf(trimPrefix) == 0 ) {
00108                                         name = name.Substring(trimPrefix.Length);
00109                                 }
00110                                 
00111                                 if (Path.IsPathRooted(name) == true) {
00112                                         // NOTE:
00113                                         // for UNC names...  \\machine\share\zoom\beet.txt gives \zoom\beet.txt
00114                                         name = name.Substring(Path.GetPathRoot(name).Length);
00115                                 }
00116                                 
00117                                 if (relativePath == true) {
00118                                         if (name.Length > 0 && (name[0] == Path.AltDirectorySeparatorChar || name[0] == Path.DirectorySeparatorChar)) {
00119                                                 name = name.Remove(0, 1);
00120                                         }
00121                                 } else {
00122                                         if (name.Length > 0 && name[0] != Path.AltDirectorySeparatorChar && name[0] != Path.DirectorySeparatorChar) {
00123                                                 name = name.Insert(0, "/");
00124                                         }
00125                                 }
00126                                 name = name.Replace(@"\", "/");
00127                         }
00128                         else {
00129                                 name = "";
00130                         }
00131                         return name;
00132                 }
00133 
00134                 string trimPrefix;
00135                 
00139                 public string TrimPrefix
00140                 {
00141                         get { return trimPrefix; }
00142                         set { trimPrefix = value; }
00143                 }
00144                 
00145                 bool relativePath;
00146         }
00147 }

Generated on Fri Jun 23 21:50:05 2006 for OblivionModTranslator by  doxygen 1.4.6-NO