Exemple #1
0
        static void DoCopy(string folder, FileInfo f)
        {
            string targ = Path.Combine(folder, f.Name);

            ModManagement.DoMessage(string.Format(System.Globalization.CultureInfo.CurrentCulture, AMLResources.Properties.Resources.Copying, f.Name, targ));

            FileHelper.Copy(f.FullName, targ);
        }
Exemple #2
0
        public bool InstallMod(ModConfiguration mod, string source)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString());
            }
            bool retVal = false;

            if (mod != null && !string.IsNullOrEmpty(source))
            {
                if (ModAlreadyInstalled(mod.ID))
                {
                    retVal = false;
                }
                else
                {
                    if (!VersionOK(source))
                    {
                        return(false);
                    }
                    FileHelper.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);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
Exemple #5
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());
            }
        }