예제 #1
0
 static InstalledModConfigurations()
 {
     if (_log.IsDebugEnabled)
     {
         _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString());
     }
     Locations.CreatePath(Locations.InstalledModsPath);
     Instance = new InstalledModConfigurations();
     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 bool InstallMod(ModConfiguration mod, string source)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString());
            }
            bool retVal = false;

            if (ModAlreadyInstalled(mod.ID))
            {
                retVal = false;
            }
            else
            {
                if (!VersionOK(source))
                {
                    return(false);
                }
                Locations.CreatePath(Locations.ArtemisCopyPath);
                string         src  = source;
                FileAttributes attr = File.GetAttributes(src);

                if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    ModManagement.DoMessage(AMLResources.Properties.Resources.InstallingMod);
                    mod.InstallMod(src);
                }
                else if (src.EndsWith("EXE", StringComparison.OrdinalIgnoreCase))
                {
                    ModManagement.DoMessage(AMLResources.Properties.Resources.InstallingMod);
                    InstallEXE(mod, src);
                }
                else
                {
                    ModManagement.DoMessage(AMLResources.Properties.Resources.UnpackagingMod);
                    src = mod.Unpackage(source);
                    if (string.IsNullOrEmpty(src))
                    {
                        return(false);
                    }
                }
                this.Dispatcher.BeginInvoke(new Action <ModConfiguration>(AddToCollection), mod);

                retVal = true;
            }
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString());
            }
            return(retVal);
        }
예제 #4
0
        public void InstallMod(string sourceRootPath)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString());
            }
            SetInstalledPath();

            Locations.CreatePath(InstalledPath);

            Locations.CopyFiles(new DirectoryInfo(sourceRootPath), InstalledPath);
            //Now update file that stores list of installed mods, storing "targetRootPath" location.
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString());
            }
        }
예제 #5
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);
        }