예제 #1
0
        public void DeactivateSubMod()
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString());
            }
            List <FileMap> files = new List <FileMap>();

            foreach (FileMap m in ActiveFiles)
            {
                if (m.ForSubMod)
                {
                    files.Add(m);
                }
            }
            foreach (FileMap m in files)
            {
                Locations.DeleteFile(m.Target);
                ActiveFiles.Remove(m);
            }
            foreach (SubMod sm in SubMods)
            {
                if (sm.IsActive)
                {
                    sm.IsActive = false;
                    break;
                }
            }
            ActiveSubMod = null;
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString());
            }
        }
예제 #2
0
        static void DoCopy(string folder, FileInfo f)
        {
            Locations.CreatePath(folder);
            string targ = Path.Combine(folder, f.Name);

            Locations.DeleteFile(targ);
            if (_log.IsInfoEnabled)
            {
                _log.InfoFormat("Copying file from \"{0}\" to \"{1}\".", f.FullName, targ);
            }
            ModManagement.DoMessage(string.Format(System.Globalization.CultureInfo.CurrentCulture, AMLResources.Properties.Resources.Copying, f.Name, targ));
            f.CopyTo(targ);
        }
예제 #3
0
        public void ActivateMod()
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString());
            }
            string targetRootPath = Locations.ArtemisCopyPath;
            List <KeyValuePair <string, string> > targetList = new List <KeyValuePair <string, string> >();

            if (string.IsNullOrEmpty(InstalledPath))
            {
                SetInstalledPath();
            }
            targetList.AddRange(Locations.CopyFiles(new DirectoryInfo(InstalledPath), targetRootPath));
            foreach (FileMap m in BaseFiles)
            {
                if (m.Source.Contains("*") || m.Source.Contains("?"))
                {
                    //more than one file, wildcarded.
                    string sourceFle = m.Source;

                    int i = sourceFle.LastIndexOf('\\');
                    sourceFle = sourceFle.Substring(0, i);
                    targetList.AddRange(Locations.CopyFiles(
                                            new DirectoryInfo(Path.Combine(InstalledPath, sourceFle)),
                                            Path.Combine(targetRootPath, m.Target)));
                }
                else
                {
                    FileInfo src  = new FileInfo(Path.Combine(InstalledPath, m.Source));
                    string   targ = Path.Combine(Locations.ArtemisCopyPath, m.Target);
                    Locations.DeleteFile(targ);
                    src.CopyTo(targ);
                    targetList.Add(new KeyValuePair <string, string>(src.FullName, targ));
                }
            }
            ActiveFiles = new ObservableCollection <FileMap>();
            foreach (KeyValuePair <string, string> targ in targetList)
            {
                ActiveFiles.Add(new FileMap(targ.Key, targ.Value));
            }
            IsActive = true;
            if (this.SubMods != null && this.SubMods.Count > 0)
            {
                this.ActivateSubMod(SubMods[0].Title);
            }
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString());
            }
        }
예제 #4
0
 /// <summary>
 /// Deactivates the mod.
 /// </summary>
 /// <param name="rootPath">The root path. (Location where mod is activated at).</param>
 public void DeactivateMod()
 {
     if (_log.IsDebugEnabled)
     {
         _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString());
     }
     //After deactivating mod, parent caller needs to then go through all remaining mods (including stock) and ensure
     // all files exist.
     foreach (FileMap m in ActiveFiles)
     {
         Locations.DeleteFile(m.Target);
     }
     ActiveFiles.Clear();
     if (_log.IsDebugEnabled)
     {
         _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString());
     }
 }
예제 #5
0
        public static List <KeyValuePair <string, string> > CopyFiles(DirectoryInfo source, string targetPath, string searchPattern)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString());
            }
            List <KeyValuePair <string, string> > targets = new List <KeyValuePair <string, string> >();

            if (source != null)
            {
                string root = null;
                foreach (FileInfo f in source.GetFiles(searchPattern, SearchOption.AllDirectories))
                {
                    if (root == null)
                    {
                        root = source.FullName;
                    }
                    string relative = f.DirectoryName.Substring(root.Length);
                    while (relative.StartsWith("\\", StringComparison.OrdinalIgnoreCase))
                    {
                        relative = relative.Substring(1);
                    }
                    while (relative.EndsWith("\\", StringComparison.OrdinalIgnoreCase))
                    {
                        relative = relative.Substring(0, relative.Length - 1);
                    }
                    string target = Path.Combine(targetPath, relative);
                    CreatePath(target);
                    target = Path.Combine(target, f.Name);
                    Locations.DeleteFile(target);
                    targets.Add(new KeyValuePair <string, string>(f.FullName, target));
                    if (_log.IsInfoEnabled)
                    {
                        _log.InfoFormat("Copying \"{0}\" to \"{1}\"", f.FullName, target);
                    }
                    f.CopyTo(target);
                }
            }
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString());
            }
            return(targets);
        }
예제 #6
0
 public static void DeleteAllFiles(string target)
 {
     if (_log.IsDebugEnabled)
     {
         _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString());
     }
     if (Directory.Exists(target))
     {
         foreach (FileInfo f in new DirectoryInfo(target).GetFiles("*.*", SearchOption.AllDirectories))
         {
             Locations.DeleteFile(f.FullName);
         }
         DeleteDirectoryTree(target);
     }
     if (_log.IsDebugEnabled)
     {
         _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString());
     }
 }
예제 #7
0
        public void ActivateSubMod(string SubModTitle)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString());
            }
            if (string.IsNullOrEmpty(InstalledPath))
            {
                SetInstalledPath();
            }
            //Must first make sure the Mod itself is activated.
            string targetRootPath = Locations.ArtemisCopyPath;
            List <KeyValuePair <string, string> > targetList = new List <KeyValuePair <string, string> >();

            if (!string.IsNullOrEmpty(ActiveSubMod) && ActiveSubMod != SubModTitle)
            {
                DeactivateSubMod();
            }
            if (ActiveSubMod != SubModTitle)
            {
                foreach (SubMod sub in SubMods)
                {
                    if (sub.Title == SubModTitle)
                    {
                        foreach (FileMap m in sub.Files)
                        {
                            // <FileMap Source="Helm UI Mod\New UI Image Files\*" Target="dat"/>

                            if (m.Source.Contains("*") || m.Source.Contains("?"))
                            {
                                //more than one file, wildcarded.

                                string sourceFle = m.Source;

                                int i = sourceFle.LastIndexOf('\\');
                                sourceFle = sourceFle.Substring(0, i);
                                targetList.AddRange(Locations.CopyFiles(
                                                        new DirectoryInfo(Path.Combine(InstalledPath, sourceFle)),
                                                        Path.Combine(targetRootPath, m.Target)));
                            }
                            else
                            {
                                FileInfo src  = new FileInfo(Path.Combine(InstalledPath, m.Source));
                                string   targ = Path.Combine(Locations.ArtemisCopyPath, m.Target);
                                Locations.DeleteFile(targ);
                                src.CopyTo(targ);
                                targetList.Add(new KeyValuePair <string, string>(src.FullName, targ));
                            }
                        }
                        ActiveSubMod = sub.Title;
                        sub.IsActive = true;
                        break;
                    }
                }
            }

            foreach (KeyValuePair <string, string> targ in targetList)
            {
                ActiveFiles.Add(
                    new FileMap(targ.Key, targ.Value, true));
            }
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString());
            }
        }
예제 #8
0
        public string Unpackage(string zipFile)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString());
            }
            string retVal = string.Empty;

            try
            {
                if (!string.IsNullOrEmpty(ID))
                {
                    SetInstalledPath();
                    retVal = InstalledPath;
                    if (!Directory.Exists(retVal))
                    {
                        Locations.CreatePath(retVal);
                    }
                    //retVal will be path to where files were unzipped.
                    // Idea:  if can control, have it unzip straight to target.

                    using (Stream stream = File.OpenRead(zipFile))
                    {
                        IReader reader = ReaderFactory.Open(stream);
                        while (reader.MoveToNextEntry())
                        {
                            if (!reader.Entry.IsDirectory)
                            {
                                string target = Path.Combine(retVal, reader.Entry.FilePath);
                                Locations.DeleteFile(target);
                                if (_log.IsInfoEnabled)
                                {
                                    _log.InfoFormat("Unpackaging {0}, writing to {1}", reader.Entry.FilePath, target);
                                }

                                //Unpackaging "{0}", writing to "{1}".

                                ModManagement.DoMessage(string.Format(System.Globalization.CultureInfo.CurrentCulture, AMLResources.Properties.Resources.Unpackaging, reader.Entry.FilePath, target));

                                reader.WriteEntryToDirectory(retVal,
                                                             SharpCompress.Common.ExtractOptions.ExtractFullPath |
                                                             SharpCompress.Common.ExtractOptions.Overwrite);

                                FileInfo f = new FileInfo(target);
                                f.LastWriteTime = reader.Entry.LastModifiedTime.Value;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (_log.IsWarnEnabled)
                {
                    _log.Warn("Error unpackaging:", ex);
                }
                retVal = string.Empty;
            }
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString());
            }
            return(retVal);
        }
예제 #9
0
        static string[] GetAllXmlFiles(string source)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString());
            }
            List <string>  retVal = new List <string>();
            FileAttributes attr   = File.GetAttributes(source);

            if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
            {
                foreach (FileInfo f in new DirectoryInfo(source).GetFiles("*" + DataStrings.XMLExtension, SearchOption.AllDirectories))
                {
                    retVal.Add(f.FullName);
                }
            }
            else if (source.EndsWith("EXE", StringComparison.OrdinalIgnoreCase))
            {
            }
            else
            {
                try
                {
                    using (Stream stream = File.OpenRead(source))
                    {
                        IReader reader = ReaderFactory.Open(stream);
                        while (reader.MoveToNextEntry())
                        {
                            if (!reader.Entry.IsDirectory)
                            {
                                if (reader.Entry.FilePath.EndsWith(DataStrings.XMLExtension, StringComparison.OrdinalIgnoreCase))
                                {
                                    string target = Path.Combine(Path.GetTempPath(), reader.Entry.FilePath);
                                    Locations.DeleteFile(target);
                                    if (_log.IsInfoEnabled)
                                    {
                                        _log.InfoFormat("Checking {0}, writing to {1}", reader.Entry.FilePath, target);
                                    }
                                    retVal.Add(target);
                                    reader.WriteEntryToDirectory(Path.GetTempPath(),
                                                                 SharpCompress.Common.ExtractOptions.ExtractFullPath |
                                                                 SharpCompress.Common.ExtractOptions.Overwrite);
                                    //reader.WriteEntryToFile(target,
                                    //    SharpCompress.Common.ExtractOptions.ExtractFullPath | SharpCompress.Common.ExtractOptions.Overwrite);
                                    FileInfo f = new FileInfo(target);
                                    f.LastWriteTime = reader.Entry.LastModifiedTime.Value;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    retVal = null;
                    if (_log.IsWarnEnabled)
                    {
                        _log.Warn("Error unpacking " + source + ".", ex);
                    }
                }
            }
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString());
            }
            if (retVal != null)
            {
                return(retVal.ToArray());
            }
            else
            {
                return(null);
            }
        }