Beispiel #1
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());
            }
        }
Beispiel #2
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);
        }
Beispiel #3
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);
            }
        }
Beispiel #4
0
        private static void InstallEXE(ModConfiguration config, string file)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString());
            }
            if (string.IsNullOrEmpty(file) || !file.EndsWith(".EXE", StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidOperationException("Must be an EXE file to call InstallEXE Method.");
            }
            if (config != null)
            {
                Locations.MessageBoxShow(
                    AMLResources.Properties.Resources.EXEInstallWarning
                    + DataStrings.CRCR
                    + AMLResources.Properties.Resources.FullRestoreWarning,
                    MessageBoxButton.OK, MessageBoxImage.Information);
                //First get list of files
                ModManagement.DoMessage(AMLResources.Properties.Resources.LoadingListOfFiles);
#if EXETest
                string     testPath   = @"D:\Stuff\Downloads\Artemis backup";
                FileInfo[] PreInstall = new DirectoryInfo(testPath).GetFiles("*.*", SearchOption.AllDirectories);
#else
                FileInfo[] PreInstall = new DirectoryInfo(Locations.ArtemisInstallPath).GetFiles("*.*", SearchOption.AllDirectories);
                ModManagement.DoMessage(AMLResources.Properties.Resources.InstallingModMessage);

                RunAdminProcess(file, string.Empty);
#endif
                ModManagement.DoMessage(AMLResources.Properties.Resources.LoadingListAddedByMod);
                FileInfo[] PostInstall = new DirectoryInfo(Locations.ArtemisInstallPath).GetFiles("*.*", SearchOption.AllDirectories);
                if (VersionOK(Locations.ArtemisInstallPath))
                {
                    //Now identify what changed, and copy changed files to work path.
                    string wrkPath = Path.Combine(Locations.InstalledModsPath, config.ID);
                    if (_log.IsInfoEnabled)
                    {
                        _log.InfoFormat("Work Path set to \"{0}\"", wrkPath);
                    }
                    Dictionary <string, FileInfo> PreInstallFiles = new Dictionary <string, FileInfo>();
                    foreach (FileInfo f in PreInstall)
                    {
                        string fn = f.FullName;
#if EXETest
                        fn = fn.Replace(testPath, Locations.ArtemisInstallPath);
#endif
                        PreInstallFiles.Add(fn, f);
                    }
                    ModManagement.DoMessage(AMLResources.Properties.Resources.CopyingToModInstallation);
                    foreach (FileInfo f in PostInstall)
                    {
                        if (_log.IsInfoEnabled)
                        {
                            _log.InfoFormat("Post install file: {0}", f.FullName);
                        }
                        string relative = f.DirectoryName.Substring(Locations.ArtemisInstallPath.Length);
                        if (relative.EndsWith("\\", StringComparison.OrdinalIgnoreCase))
                        {
                            relative = relative.Substring(0, relative.Length - 1);
                        }
                        if (relative.StartsWith("\\", StringComparison.OrdinalIgnoreCase))
                        {
                            relative = relative.Substring(1, relative.Length - 1);
                        }
                        string folder = Path.Combine(wrkPath, relative);
                        if (_log.IsInfoEnabled)
                        {
                            _log.InfoFormat("Relative path = \"{1}\".  Target folder set to \"{0}\"", folder, relative);
                        }

                        if (PreInstallFiles.ContainsKey(f.FullName))
                        {
                            if (_log.IsInfoEnabled)
                            {
                                _log.Info("File found amoung preinstall.");
                            }
                            if (f.Length != PreInstallFiles[f.FullName].Length || f.LastWriteTimeUtc.CompareTo(PreInstallFiles[f.FullName].LastWriteTimeUtc) != 0)
                            {
                                if (_log.IsInfoEnabled)
                                {
                                    _log.Info("File size or last modified date not match.");
                                }
                                DoCopy(folder, f);
                            }
                            else
                            {
                                if (_log.IsInfoEnabled)
                                {
                                    _log.Info("File matches perfectly.");
                                }
                            }
                        }
                        else
                        {
                            if (_log.IsInfoEnabled)
                            {
                                _log.Info("File was not found among pre-installed files.");
                            }
                            DoCopy(folder, f);
                        }
                    }
                }
#if !EXETest
                if (!string.IsNullOrEmpty(config.Uninstall))
                {
                    ModManagement.DoMessage(AMLResources.Properties.Resources.UninstallingEXEMod);

                    RunAdminProcess(Path.Combine(Locations.ArtemisInstallPath, config.Uninstall), string.Empty);
                    System.Threading.Thread.Sleep(10000);
                }
                else
                {
                    Locations.MessageBoxShow(
                        AMLResources.Properties.Resources.PleaseRunUninstaller,
                        MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
                ModManagement.DoMessage(AMLResources.Properties.Resources.RestoringOriginalArtemis);
                // config.InstallMod(wrkPath);
                ModConfiguration stock     = new ModConfiguration(Locations.MODStockDefinition);
                string           StockPath = Path.Combine(Locations.InstalledModsPath, stock.ID);


                string xcopy = Path.Combine(Path.GetTempPath(), DataStrings.RestoreArtemisCmd);
                using (StreamWriter sw = new StreamWriter(xcopy))
                {
                    sw.WriteLine(string.Format(DataStrings.XcopyCommand, StockPath, Locations.ArtemisInstallPath));
                }
                RunAdminProcess(xcopy, string.Empty);
#endif
            }
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString());
            }
        }
        static UserConfiguration()
        {
            bool DataConverted = false;

            if (File.Exists(Locations.ConfigFile))
            {
                using (StreamReader sr = new StreamReader(Locations.ConfigFile))
                {
                    string sLine = sr.ReadLine();
                    if (!sLine.Contains("="))
                    {
                        Current = new UserConfiguration();
                        Current.ArtemisInstallPath = sLine;
                        if (!string.IsNullOrEmpty(Current.ArtemisInstallPath))
                        {
                            if (!File.Exists(Path.Combine(Current.ArtemisInstallPath, Locations.ArtemisEXE)))
                            {
                                Current.ArtemisInstallPath = Locations.FindArtemisInstallPath();
                            }
                        }
                        if (sLine != null)
                        {
                            sLine = sr.ReadLine();
                            if (!string.IsNullOrEmpty(sLine))
                            {
                                bool b;
                                if (bool.TryParse(sLine, out b))
                                {
                                    Current.UseArtemisExtender = b;
                                }
                            }
                            if (sLine != null)
                            {
                                sLine = sr.ReadLine();
                                Current.ArtemisExtenderPath = sLine;
                                if (sLine != null)
                                {
                                    sLine = sr.ReadLine();
                                    Current.ArtemisExtenderCopy = sLine;
                                }
                            }
                        }
                        DataConverted = true;
                    }
                }
            }
            if (DataConverted)
            {
                FileHelper.DeleteFile(Locations.ConfigFile);
                Current.Save();
            }
            else
            {
                Current = INIConverter.ToObject(Locations.ConfigFile, new UserConfiguration()) as UserConfiguration;
            }
            if (string.IsNullOrEmpty(Current.ArtemisExtenderCopy) || !File.Exists(Current.ArtemisExtenderCopy))
            {
                Current.UseArtemisExtender = false;
            }
            Current.Original = new UserConfiguration();

            Current.AcceptChanges();
        }