Beispiel #1
0
        public static string Download(string url, out string etag, string filename = null, IUser user = null)
        {
            TxFileManager FileTransaction = new TxFileManager();

            user = user ?? new NullUser();
            user.RaiseMessage("Downloading {0}", url);

            // Generate a temporary file if none is provided.
            if (filename == null)
            {
                filename = FileTransaction.GetTempFileName();
            }

            log.DebugFormat("Downloading {0} to {1}", url, filename);

            try
            {
                var agent = MakeDefaultHttpClient();
                agent.DownloadFile(url, filename);
                etag = agent.ResponseHeaders.Get("ETag")?.Replace("\"", "");
            }
            // Explicit redirect handling. This is needed when redirecting from HTTPS to HTTP on .NET Core.
            catch (WebException ex)
            {
                if (ex.Status != WebExceptionStatus.ProtocolError)
                {
                    throw;
                }

                HttpWebResponse response = ex.Response as HttpWebResponse;
                if (response?.StatusCode != HttpStatusCode.Redirect)
                {
                    throw;
                }

                return(Download(response.GetResponseHeader("Location"), out etag, filename, user));
            }
            catch (Exception e)
            {
                log.InfoFormat("Native download failed, trying with CurlSharp...");
                etag = null;

                try
                {
                    Curl.Init();

                    using (FileStream stream = File.OpenWrite(filename))
                    {
                        string header = string.Empty;

                        var client = Curl.CreateEasy(url, stream, delegate(byte[] buf, int size, int nmemb, object extraData)
                        {
                            header += Encoding.UTF8.GetString(buf);
                            return(size * nmemb);
                        });

                        using (client)
                        {
                            var result     = client.Perform();
                            var returnCode = client.ResponseCode;

                            if (result != CurlCode.Ok || returnCode >= 300)
                            {
                                // Always log if it's an error.
                                log.ErrorFormat("Response from {0}:\r\n\r\n{1}\r\n{2}", url, header, "Content not logged because it is likely a file.");

                                WebException curlException =
                                    new WebException($"Curl download failed with status {returnCode}.");
                                throw new NativeAndCurlDownloadFailedKraken(
                                          new List <Exception> {
                                    e, curlException
                                },
                                          url.ToString(), header, null, returnCode
                                          );
                            }
                            else
                            {
                                // Only log if debug flag is set.
                                log.DebugFormat("Response from {0}:\r\n\r\n{1}\r\n{2}", url, header, "Content not logged because it is likely a file.");
                            }
                        }
                    }

                    Curl.CleanUp();
                    return(filename);
                }
                catch
                {
                    // D'oh, failed again. Fall through to clean-up handling.
                }

                // Clean up our file, it's unlikely to be complete.
                // We do this even though we're using transactional files, as we may not be in a transaction.
                // It's okay if this fails.
                try
                {
                    log.DebugFormat("Removing {0} after web error failure", filename);
                    FileTransaction.Delete(filename);
                }
                catch
                {
                    // Apparently we need a catch, even if we do nothing.
                }

                // Look for an exception regarding the authentication.
                if (Regex.IsMatch(e.ToString(), "The authentication or decryption has failed."))
                {
                    throw new MissingCertificateKraken("Failed downloading " + url, e);
                }

                // Not the exception we were looking for! Throw it further upwards!
                throw;
            }

            return(filename);
        }
Beispiel #2
0
 /// <summary>
 /// A simple constructor that initializes the object with its dependencies.
 /// </summary>
 /// <param name="p_gmiGameModeInfo">The environment info of the current game mode.</param>
 /// <param name="p_modMod">The mod being installed.</param>
 /// <param name="p_ilgInstallLog">The install log to use to log file installations.</param>
 /// <param name="p_pmgPluginManager">The plugin manager.</param>
 /// <param name="p_dfuDataFileUtility">The utility class to use to work with data files.</param>
 /// <param name="p_tfmFileManager">The transactional file manager to use to interact with the file system.</param>
 /// <param name="p_dlgOverwriteConfirmationDelegate">The method to call in order to confirm an overwrite.</param>
 /// <param name="p_UsesPlugins">Game using plugin or mods (True for plugins).</param>
 /// <param name="p_eifEnvironmentInfo">Environment info for the entire program.</param>
 public ModFileUpgradeInstaller(IGameModeEnvironmentInfo p_gmiGameModeInfo, IMod p_modMod, IInstallLog p_ilgInstallLog, IPluginManager p_pmgPluginManager, IDataFileUtil p_dfuDataFileUtility, TxFileManager p_tfmFileManager, ConfirmItemOverwriteDelegate p_dlgOverwriteConfirmationDelegate, bool p_UsesPlugins, IEnvironmentInfo p_eifEnvironmentInfo)
     : base(p_gmiGameModeInfo, p_modMod, p_ilgInstallLog, p_pmgPluginManager, p_dfuDataFileUtility, p_tfmFileManager, p_dlgOverwriteConfirmationDelegate, p_UsesPlugins, p_eifEnvironmentInfo)
 {
     OriginallyInstalledFiles = new Set <string>(StringComparer.OrdinalIgnoreCase);
     foreach (string strFile in InstallLog.GetInstalledModFiles(Mod))
     {
         OriginallyInstalledFiles.Add(strFile.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar));
     }
 }
Beispiel #3
0
        public static string Download(string url, out string etag, string filename = null, IUser user = null)
        {
            TxFileManager FileTransaction = new TxFileManager();

            user = user ?? new NullUser();
            user.RaiseMessage("Downloading {0}", url);

            // Generate a temporary file if none is provided.
            if (filename == null)
            {
                filename = FileTransaction.GetTempFileName();
            }

            log.DebugFormat("Downloading {0} to {1}", url, filename);

            try
            {
                var agent = MakeDefaultHttpClient();
                agent.DownloadFile(url, filename);
                etag = agent.ResponseHeaders.Get("ETag")?.Replace("\"", "");
            }
            catch (Exception ex)
            {
                log.InfoFormat("Download failed, trying with curlsharp...");
                etag = null;

                try
                {
                    Curl.Init();

                    using (FileStream stream = File.OpenWrite(filename))
                        using (var curl = Curl.CreateEasy(url, stream))
                        {
                            CurlCode result = curl.Perform();
                            if (result != CurlCode.Ok)
                            {
                                throw new Kraken("curl download of " + url + " failed with CurlCode " + result);
                            }
                            else
                            {
                                log.Debug("curlsharp download successful");
                            }
                        }

                    Curl.CleanUp();
                    return(filename);
                }
                catch
                {
                    // D'oh, failed again. Fall through to clean-up handling.
                }

                // Clean up our file, it's unlikely to be complete.
                // We do this even though we're using transactional files, as we may not be in a transaction.
                // It's okay if this fails.
                try
                {
                    log.DebugFormat("Removing {0} after web error failure", filename);
                    FileTransaction.Delete(filename);
                }
                catch
                {
                    // Apparently we need a catch, even if we do nothing.
                }

                // Look for an exception regarding the authentication.
                if (Regex.IsMatch(ex.ToString(), "The authentication or decryption has failed."))
                {
                    throw new MissingCertificateKraken("Failed downloading " + url, ex);
                }

                // Not the exception we were looking for! Throw it further upwards!
                throw;
            }

            return(filename);
        }
Beispiel #4
0
        static int DoInstall(string game, string filename, string installationPath, string profilePath, string gamePath,
                             List <string> additionalSearchPaths, string seVersion, ref string errorString)
        {
            if (game == null)
            {
                errorString = "no game specified";
                return(1);
            }
            if (filename == null)
            {
                errorString = "no file specified";
                return(1);
            }
            if (profilePath == null)
            {
                errorString = "no profile path specified";
                return(1);
            }
            if (gamePath == null)
            {
                errorString = "no game path specified";
                return(1);
            }
            try
            {
                EnvironmentInfo = new EnvironmentInfo(Properties.Settings.Default);

                string   exeLocation = Assembly.GetExecutingAssembly().Location;
                string   exePath     = System.IO.Path.GetDirectoryName(exeLocation);
                string[] gameModes   = Directory.GetFiles(Path.Combine(exePath, "GameModes"), String.Format("{0}.dll", game));
                if (gameModes.Count() == 0)
                {
                    errorString = "unknown game";
                    return(1);
                }

                Assembly         gameAssembly    = Assembly.LoadFrom(gameModes[0]);
                IGameModeFactory gameModeFactory = null;
                Type[]           exportedTypes   = gameAssembly.GetExportedTypes();
                foreach (Type type in exportedTypes)
                {
                    if (typeof(IGameModeFactory).IsAssignableFrom(type) && !type.IsAbstract)
                    {
                        ConstructorInfo constructor = type.GetConstructor(new Type[] { typeof(EnvironmentInfo) });
                        gameModeFactory = (IGameModeFactory)constructor.Invoke(new Object[] { EnvironmentInfo });
                    }
                }
                if (gameModeFactory == null)
                {
                    errorString = "invalid game";
                    return(1);
                }

                string str7zPath = Path.Combine(EnvironmentInfo.ProgrammeInfoDirectory, EnvironmentInfo.Is64BitProcess ? "7z-64bit.dll" : "7z-32bit.dll");
                SevenZipCompressor.SetLibraryPath(str7zPath);

                FileUtil fileUtil = new NexusFileUtil(EnvironmentInfo);

                EnvironmentInfo.Settings.InstallationPaths[gameModeFactory.GameModeDescriptor.ModeId] = installationPath;
                EnvironmentInfo.Settings.ModFolder[gameModeFactory.GameModeDescriptor.ModeId]         = installationPath;
                //                environmentInfo.Settings.InstallInfoFolder[gameModeFactory.GameModeDescriptor.ModeId] = environmentInfo.TemporaryPath;
                EnvironmentInfo.Settings.InstallInfoFolder[gameModeFactory.GameModeDescriptor.ModeId] = Path.Combine(installationPath, "temp");
                if (EnvironmentInfo.Settings.DelayedSettings[gameModeFactory.GameModeDescriptor.ModeId] == null)
                {
                    EnvironmentInfo.Settings.DelayedSettings[gameModeFactory.GameModeDescriptor.ModeId] = new KeyedSettings <string>();
                }
                if (EnvironmentInfo.Settings.DelayedSettings["ALL"] == null)
                {
                    EnvironmentInfo.Settings.DelayedSettings["ALL"] = new KeyedSettings <string>();
                }

                ViewMessage warning = null;

                IGameMode gameMode = gameModeFactory.BuildGameMode(fileUtil, out warning);

                IModCacheManager cacheManager = new NexusModCacheManager(EnvironmentInfo.TemporaryPath, gameMode.GameModeEnvironmentInfo.ModDirectory, fileUtil, EnvironmentInfo);

                IScriptTypeRegistry scriptTypeRegistry = ScriptTypeRegistry.DiscoverScriptTypes(Path.Combine(Path.GetDirectoryName(exeLocation), "ScriptTypes"), gameMode, new List <string>());
                if (scriptTypeRegistry.Types.Count == 0)
                {
                    errorString = "No script types were found.";
                    return(2);
                }

                // use a proxy so we can intercept accesses to the IGameMode interface. This allows us to make the additional search paths accessible from
                // the sandbox and feed in the script extender version even though the nmm lib won't find it.
                // This has to happen after DiscoverScriptTypes becaus that function tries to localize the assembly which fails for the dynamic assembly
                // of the proxy. Fortunately DiscoverScriptTypes has no side-effects on the gameMode.
                // This recreates the gamemode object so it's important no code above modifies gameMode
                ProxyGenerator      generator   = new ProxyGenerator();
                GameModeInterceptor interceptor = new GameModeInterceptor(additionalSearchPaths, seVersion != null ? new Version(seVersion) : null);

                gameMode = (IGameMode)generator.CreateClassProxy(gameMode.GetType(), new object[] { EnvironmentInfo, fileUtil }, new IInterceptor[] { interceptor });

                IModFormatRegistry formatRegistry = ModFormatRegistry.DiscoverFormats(cacheManager, gameMode.SupportedFormats, scriptTypeRegistry, Path.Combine(Path.GetDirectoryName(exeLocation), "ModFormats"));
                if (formatRegistry.Formats.Count == 0)
                {
                    errorString = "No formats were found.";
                    return(2);
                }

                // we install the mod from the temporary path. Unfortunately this requires the archive to be copied, otherwise the sandbox will
                // prevent the installer script from accessing the archive in its original location
                string fileNameTemporary = Path.Combine(EnvironmentInfo.TemporaryPath, Path.GetFileName(filename));
                File.Copy(filename, fileNameTemporary);
                IMod mod = CreateMod(fileNameTemporary, formatRegistry, gameMode);
                if (mod == null)
                {
                    errorString = "failed to initialize mod";
                    return(3);
                }

                System.IO.File.WriteAllText(installationPath + "/__installInfo.txt", mod.ModName + "\n" + mod.HumanReadableVersion + "\n" + mod.Id);

                if (mod.HasInstallScript)
                {
                    //SevenZipExtractor extractor = new SevenZipExtractor(fileNameTemporary);
                    string extractPath = Path.Combine(EnvironmentInfo.TemporaryPath, Path.GetFileNameWithoutExtension(filename));
                    //extractor.ExtractArchive(extractPath);
                    DummyDataFileUtilFactory dummyFactory = null;
                    IDataFileUtil            dataFileUtility;
                    Logger.Info("Detected C# script that relies on files in the actual data folder");

                    string modlistFile = Path.Combine(profilePath, "modlist.txt");
                    // ASSUMED mods path is the parent directory of the gameMode.InstallationPath
                    string modsPath = Directory.GetParent(gameMode.InstallationPath).FullName;
                    // Prepare dummy data directory
                    dummyFactory    = new DummyDataFileUtilFactory(gameMode.GameModeEnvironmentInfo.InstallationPath, modlistFile, modsPath, gamePath, additionalSearchPaths);
                    dataFileUtility = dummyFactory.CreateDummyDataFileUtil();

                    TxFileManager  fileManager     = new TxFileManager();
                    IInstallLog    installLog      = new DummyInstallLog();
                    IIniInstaller  iniIniInstaller = new IniInstaller(mod, installLog, fileManager, delegate { return(OverwriteResult.No); });
                    IPluginManager pluginManager   = new DummyPluginManager(Path.Combine(profilePath, "plugins.txt"), gameMode, mod);
                    IGameSpecificValueInstaller gameSpecificValueInstaller = gameMode.GetGameSpecificValueInstaller(mod, installLog, fileManager, new NexusFileUtil(EnvironmentInfo), delegate { return(OverwriteResult.No); });
                    IModFileInstaller           fileInstaller = new ModFileInstaller(gameMode.GameModeEnvironmentInfo, mod, installLog, pluginManager, dataFileUtility, fileManager, delegate { return(OverwriteResult.No); }, false, extractPath, gameMode.StopFolders);
                    InstallerGroup       installers           = new InstallerGroup(dataFileUtility, fileInstaller, iniIniInstaller, gameSpecificValueInstaller, pluginManager);
                    IVirtualModActivator modActivator         = new DummyVirtualModActivator(gameMode, EnvironmentInfo);
                    IScriptExecutor      executor             = mod.InstallScript.Type.CreateExecutor(mod, gameMode, EnvironmentInfo, modActivator, installers, SynchronizationContext.Current);
                    // run the script in a second thread and start the main loop in the main thread to ensure we can handle message boxes and the like
                    ScriptRunner runner = new ScriptRunner(executor, mod.InstallScript);

                    runner.Execute();
                    runner.TaskEnded += delegate
                    {
                        fileInstaller.FinalizeInstall();
                        iniIniInstaller.FinalizeInstall();
                        gameSpecificValueInstaller.FinalizeInstall();

                        Application.Exit();
                    };

                    Application.Run();
                    switch (runner.Status)
                    {
                    case BackgroundTasks.TaskStatus.Cancelled: return(11);

                    case BackgroundTasks.TaskStatus.Error: return(6);

                    case BackgroundTasks.TaskStatus.Incomplete: return(10);

                    default: return(0);
                    }
                }
                else
                {
                    errorString = "no install script";
                    return(4);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("exception: " + e.Message);
                MessageBox.Show(e.Message, "Installation failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(5);
            }
        }
Beispiel #5
0
        static void RunStressTest()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            {
                // Pre-test checks
                string       tempDir;
                IFileManager fm = new TxFileManager();
                using (TransactionScope s1 = new TransactionScope())
                {
                    tempDir = (new DirectoryInfo(fm.CreateTempDirectory())).Parent.FullName;
                    Console.WriteLine("Temp path: " + tempDir);
                }

                string[] directories = Directory.GetDirectories(tempDir);
                string[] files       = Directory.GetFiles(tempDir);
                if (directories.Length > 0 || files.Length > 0)
                {
                    Console.WriteLine(string.Format("ERROR  Please ensure temp path {0} has no children before running this test.", tempDir));
                    return;
                }
            }

            // Start each test in its own thread and repeat for a few interations
            const int    numThreads = 10;
            const int    iterations = 250;
            const string text       = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

            long count = 0;

            IList <Thread> threads = new List <Thread>();

            for (int i = 0; i < numThreads; i++)
            {
                Thread t = new Thread(() =>
                {
                    IFileManager fm = new TxFileManager();
                    for (int j = 0; j < iterations; j++)
                    {
                        using (TransactionScope s1 = new TransactionScope())
                        {
                            TransactionOptions to = new TransactionOptions();
                            to.Timeout            = TimeSpan.FromMinutes(30);

                            long myCount = Interlocked.Increment(ref count);
                            if (myCount % 250 == 0)
                            {
                                Console.WriteLine(myCount + " (" + myCount * 100 / (numThreads * iterations) + " %)");
                            }

                            string f1 = fm.CreateTempFileName();
                            string f2 = fm.CreateTempFileName();
                            string d1 = fm.CreateTempDirectory();

                            if (i % 100 == 0)
                            {
                                Console.WriteLine(i);
                            }

                            fm.AppendAllText(f1, text);
                            fm.Copy(f1, f2, false);

                            fm.CreateDirectory(d1);
                            fm.Delete(f2);
                            fm.DeleteDirectory(d1);
                            bool b1   = fm.DirectoryExists(d1);
                            bool b2   = fm.FileExists(f1);
                            string f3 = fm.CreateTempFileName();
                            fm.Move(f1, f3);
                            string f4 = fm.CreateTempFileName();
                            fm.Snapshot(f4);
                            fm.WriteAllBytes(f4, new byte[] { 64, 65 });
                            string f5 = fm.CreateTempFileName();
                            fm.WriteAllText(f5, text);

                            fm.Delete(f1);
                            fm.Delete(f2);
                            fm.Delete(f3);
                            fm.Delete(f4);
                            fm.Delete(f5);
                            fm.DeleteDirectory(d1);
                            s1.Complete();
                        }
                    }
                });

                threads.Add(t);
            }

            foreach (Thread t in threads)
            {
                t.Start();
            }

            Console.WriteLine("All threads started.");

            foreach (Thread t in threads)
            {
                t.Join();
            }

            sw.Stop();

            Console.WriteLine("All threads joined. Elapsed: {0}.", sw.ElapsedMilliseconds);
        }
 /// <summary>
 /// Gets the installer to use to install game specific values.
 /// </summary>
 /// <param name="p_modMod">The mod being installed.</param>
 /// <param name="p_ilgInstallLog">The install log to use to log the installation of the game specific values.</param>
 /// <param name="p_tfmFileManager">The transactional file manager to use to interact with the file system.</param>
 /// <returns>The installer to use to manage game specific values, or <c>null</c> if the game mode does not
 /// install any game specific values.</returns>
 /// <param name="p_futFileUtility">The file utility class.</param>
 /// <param name="p_dlgOverwriteConfirmationDelegate">The method to call in order to confirm an overwrite.</param>
 public abstract IGameSpecificValueInstaller GetGameSpecificValueInstaller(IMod p_modMod, IInstallLog p_ilgInstallLog, TxFileManager p_tfmFileManager, FileUtil p_futFileUtility, ConfirmItemOverwriteDelegate p_dlgOverwriteConfirmationDelegate);
Beispiel #7
0
        /// <summary>
        /// Create a new fake KSP instance
        /// </summary>
        /// <param name="game">The game of the new instance.</param>
        /// <param name="newName">The name for the new instance.</param>
        /// <param name="newPath">The location of the new instance.</param>
        /// <param name="version">The version of the new instance. Should have a build number.</param>
        /// <param name="dlcs">The IDlcDetector implementations for the DLCs that should be faked and the requested dlc version as a dictionary.</param>
        /// <exception cref="InstanceNameTakenKraken">Thrown if the instance name is already in use.</exception>
        /// <exception cref="NotKSPDirKraken">Thrown by AddInstance() if created instance is not valid, e.g. if a write operation didn't complete for whatever reason.</exception>
        public void FakeInstance(IGame game, string newName, string newPath, GameVersion version, Dictionary <DLC.IDlcDetector, GameVersion> dlcs = null)
        {
            TxFileManager fileMgr = new TxFileManager();

            using (TransactionScope transaction = CkanTransaction.CreateTransactionScope())
            {
                if (HasInstance(newName))
                {
                    throw new InstanceNameTakenKraken(newName);
                }


                if (!version.InBuildMap(game))
                {
                    throw new BadGameVersionKraken(String.Format("The specified KSP version is not a known version: {0}", version.ToString()));
                }
                if (Directory.Exists(newPath) && (Directory.GetFiles(newPath).Length != 0 || Directory.GetDirectories(newPath).Length != 0))
                {
                    throw new BadInstallLocationKraken("The specified folder already exists and is not empty.");
                }

                log.DebugFormat("Creating folder structure and text files at {0} for KSP version {1}", Path.GetFullPath(newPath), version.ToString());

                // Create a KSP root directory, containing a GameData folder, a buildID.txt/buildID64.txt and a readme.txt
                fileMgr.CreateDirectory(newPath);
                fileMgr.CreateDirectory(Path.Combine(newPath, "GameData"));
                fileMgr.CreateDirectory(Path.Combine(newPath, "Ships"));
                fileMgr.CreateDirectory(Path.Combine(newPath, "Ships", "VAB"));
                fileMgr.CreateDirectory(Path.Combine(newPath, "Ships", "SPH"));
                fileMgr.CreateDirectory(Path.Combine(newPath, "Ships", "@thumbs"));
                fileMgr.CreateDirectory(Path.Combine(newPath, "Ships", "@thumbs", "VAB"));
                fileMgr.CreateDirectory(Path.Combine(newPath, "Ships", "@thumbs", "SPH"));
                fileMgr.CreateDirectory(Path.Combine(newPath, "saves"));
                fileMgr.CreateDirectory(Path.Combine(newPath, "saves", "scenarios"));
                fileMgr.CreateDirectory(Path.Combine(newPath, "saves", "training"));

                // Don't write the buildID.txts if we have no build, otherwise it would be -1.
                if (version.IsBuildDefined)
                {
                    fileMgr.WriteAllText(Path.Combine(newPath, "buildID.txt"), String.Format("build id = {0}", version.Build));
                    fileMgr.WriteAllText(Path.Combine(newPath, "buildID64.txt"), String.Format("build id = {0}", version.Build));
                }

                // Create the readme.txt WITHOUT build number.
                fileMgr.WriteAllText(Path.Combine(newPath, "readme.txt"), String.Format("Version {0}", new GameVersion(version.Major, version.Minor, version.Patch).ToString()));

                // Create the needed folder structure and the readme.txt for DLCs that should be simulated.
                if (dlcs != null)
                {
                    foreach (KeyValuePair <DLC.IDlcDetector, GameVersion> dlc in dlcs)
                    {
                        DLC.IDlcDetector dlcDetector = dlc.Key;
                        GameVersion      dlcVersion  = dlc.Value;

                        if (!dlcDetector.AllowedOnBaseVersion(version))
                        {
                            throw new WrongGameVersionKraken(
                                      version,
                                      String.Format("KSP version {0} or above is needed for {1} DLC.",
                                                    dlcDetector.ReleaseGameVersion,
                                                    dlcDetector.IdentifierBaseName
                                                    ));
                        }

                        string dlcDir = Path.Combine(newPath, dlcDetector.InstallPath());
                        fileMgr.CreateDirectory(dlcDir);
                        fileMgr.WriteAllText(
                            Path.Combine(dlcDir, "readme.txt"),
                            String.Format("Version {0}", dlcVersion));
                    }
                }

                // Add the new instance to the config
                GameInstance new_instance = new GameInstance(game, newPath, newName, User, false);
                AddInstance(new_instance);
                transaction.Complete();
            }
        }
        private XElement SaveToDisk(IResource resource, StringBuilder contents, string directoryName, TxFileManager fileManager)
        {
            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }

            if (_dev2FileWrapper.Exists(resource.FilePath))
            {
                // Remove readonly attribute if it is set
                var attributes = _dev2FileWrapper.GetAttributes(resource.FilePath);
                if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                {
                    _dev2FileWrapper.SetAttributes(resource.FilePath, attributes ^ FileAttributes.ReadOnly);
                }
            }

            XElement xml = contents.ToXElement();

            xml = resource.UpgradeXml(xml, resource);
            StringBuilder result = xml.ToStringBuilder();

            var signedXml = HostSecurityProvider.Instance.SignXml(result);

            lock (Common.GetFileLock(resource.FilePath))
            {
                signedXml.WriteToFile(resource.FilePath, Encoding.UTF8, fileManager);
            }
            return(xml);
        }
        private static bool AddToCatalog(IResource resource, List <IResource> resources, TxFileManager fileManager, XElement xml)
        {
            var index   = resources.IndexOf(resource);
            var updated = false;

            if (index != -1)
            {
                var existing = resources[index];
                if (!string.Equals(existing.FilePath, resource.FilePath, StringComparison.CurrentCultureIgnoreCase))
                {
                    fileManager.Delete(existing.FilePath);
                }
                resources.RemoveAt(index);
                updated = true;
            }
            resource.GetInputsOutputs(xml);
            resource.ReadDataList(xml);
            resource.SetIsNew(xml);
            resource.UpdateErrorsBasedOnXML(xml);

            resources.Add(resource);
            return(updated);
        }
Beispiel #10
0
        public static string Download(string url, out string etag, string filename = null, IUser user = null)
        {
            TxFileManager FileTransaction = new TxFileManager();

            user = user ?? new NullUser();
            user.RaiseMessage("Downloading {0}", url);

            // Generate a temporary file if none is provided.
            if (filename == null)
            {
                filename = FileTransaction.GetTempFileName();
            }

            log.DebugFormat("Downloading {0} to {1}", url, filename);

            try
            {
                var agent = MakeDefaultHttpClient();
                agent.DownloadFile(url, filename);
                etag = agent.ResponseHeaders.Get("ETag")?.Replace("\"", "");
            }
            catch (Exception exc)
            {
                var wexc = exc as WebException;
                if (wexc?.Status == WebExceptionStatus.ProtocolError)
                {
                    // Get redirect if redirected.
                    // This is needed when redirecting from HTTPS to HTTP on .NET Core.
                    var response = wexc.Response as HttpWebResponse;
                    if (response?.StatusCode == HttpStatusCode.Redirect)
                    {
                        return(Download(response.GetResponseHeader("Location"), out etag, filename, user));
                    }
                    // Otherwise it's a valid failure from the server (probably a 404), keep it
                }

                // Clean up our file, it's unlikely to be complete.
                // We do this even though we're using transactional files, as we may not be in a transaction.
                // It's okay if this fails.
                try
                {
                    log.DebugFormat("Removing {0} after web error failure", filename);
                    FileTransaction.Delete(filename);
                }
                catch
                {
                    // Apparently we need a catch, even if we do nothing.
                }

                // Look for an exception regarding the authentication.
                if (Regex.IsMatch(exc.ToString(), "The authentication or decryption has failed."))
                {
                    throw new MissingCertificateKraken("Failed downloading " + url, exc);
                }

                // Not the exception we were looking for! Throw it further upwards!
                throw;
            }

            return(filename);
        }
 /// <summary>
 /// A simple constructor that initializes the object with its dependencies.
 /// </summary>
 /// <param name="p_gmiGameModeInfo">The environment info of the current game mode.</param>
 /// <param name="p_modMod">The mod being installed.</param>
 /// <param name="p_ilgInstallLog">The install log to use to log file installations.</param>
 /// <param name="p_pmgPluginManager">The plugin manager.</param>
 /// <param name="p_dfuDataFileUtility">The utility class to use to work with data files.</param>
 /// <param name="p_tfmFileManager">The transactional file manager to use to interact with the file system.</param>
 /// <param name="p_dlgOverwriteConfirmationDelegate">The method to call in order to confirm an overwrite.</param>
 /// <param name="p_UsesPlugins">Whether the file is a mod or a plugin.</param>
 public ModFileInstaller(IGameModeEnvironmentInfo p_gmiGameModeInfo, IMod p_modMod, IInstallLog p_ilgInstallLog, IPluginManager p_pmgPluginManager, IDataFileUtil p_dfuDataFileUtility, TxFileManager p_tfmFileManager, ConfirmItemOverwriteDelegate p_dlgOverwriteConfirmationDelegate, bool p_UsesPlugins, ModManager p_mmModManager)
 {
     GameModeInfo                       = p_gmiGameModeInfo;
     Mod                                = p_modMod;
     InstallLog                         = p_ilgInstallLog;
     PluginManager                      = p_pmgPluginManager;
     DataFileUtility                    = p_dfuDataFileUtility;
     TransactionalFileManager           = p_tfmFileManager;
     m_dlgOverwriteConfirmationDelegate = p_dlgOverwriteConfirmationDelegate ?? ((s, b, m) => OverwriteResult.No);
     IsPlugin                           = p_UsesPlugins;
     m_mmModManager                     = p_mmModManager;
 }
Beispiel #12
0
        private void BuildCatalogFromWorkspace(string workspacePath, string[] folders, List <ResourceBuilderTO> streams)
        {
            foreach (var path in folders.Where(f => !string.IsNullOrEmpty(f)).Select(f => Path.Combine(workspacePath, f)))
            {
                if (!Directory.Exists(path))
                {
                    continue;
                }

                var files = DirectoryHelper.GetFilesByExtensions(path, ".xml", ".bite");
                foreach (var file in files)
                {
                    var fa = File.GetAttributes(file);

                    if ((fa & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                    {
                        Dev2Logger.Info("Removed READONLY Flag from [ " + file + " ]", GlobalConstants.WarewolfInfo);
                        File.SetAttributes(file, FileAttributes.Normal);
                    }

                    // Use the FileStream class, which has an option that causes asynchronous I/O to occur at the operating system level.
                    // In many cases, this will avoid blocking a ThreadPool thread.
                    var sourceStream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096, true);
                    streams.Add(new ResourceBuilderTO {
                        FilePath = file, FileStream = sourceStream
                    });
                }
            }

            // Use the parallel task library to process file system ;)
            IList <Type> allTypes             = new List <Type>();
            var          connectionTypeName   = typeof(Connection).Name;
            var          dropBoxSourceName    = typeof(DropBoxSource).Name;
            var          sharepointSourceName = typeof(SharepointSource).Name;
            var          dbType = typeof(DbSource).Name;

            try
            {
                var resourceBaseType = typeof(IResourceSource);
                var assemblies       = AppDomain.CurrentDomain.GetAssemblies();
                var types            = assemblies
                                       .SelectMany(s => s.GetTypes())
                                       .Where(p => resourceBaseType.IsAssignableFrom(p));
                allTypes = types as IList <Type> ?? types.ToList();
            }
            catch (Exception e)
            {
                Dev2Logger.Error(ErrorResource.ErrorLoadingTypes, e, GlobalConstants.WarewolfError);
            }
            streams.ForEach(currentItem =>
            {
                XElement xml = null;
                try
                {
                    xml = XElement.Load(currentItem.FileStream);
                }
                catch (Exception e)
                {
                    Dev2Logger.Error("Resource [ " + currentItem.FilePath + " ] caused " + e.Message, GlobalConstants.WarewolfError);
                }

                var result = xml?.ToStringBuilder();

                var isValid  = result != null && HostSecurityProvider.Instance.VerifyXml(result);
                var typeName = xml?.AttributeSafe("Type");
                if (isValid)
                {
                    //TODO: Remove this after V1 is released. All will be updated.
                    #region old typing to be removed after V1
                    if (!IsWarewolfResource(xml))
                    {
                        return;
                    }
                    if (typeName == "Unknown")
                    {
                        var servertype = xml.AttributeSafe("ResourceType");
                        if (servertype != null && servertype == dbType)
                        {
                            xml.SetAttributeValue("Type", dbType);
                            typeName = dbType;
                        }
                    }

                    if (typeName == "Dev2Server" || typeName == "Server" || typeName == "ServerSource")
                    {
                        xml.SetAttributeValue("Type", connectionTypeName);
                        typeName = connectionTypeName;
                    }

                    if (typeName == "OauthSource")
                    {
                        xml.SetAttributeValue("Type", dropBoxSourceName);
                        typeName = dropBoxSourceName;
                    }
                    if (typeName == "SharepointServerSource")
                    {
                        xml.SetAttributeValue("Type", sharepointSourceName);
                        typeName = sharepointSourceName;
                    }
                    #endregion

                    Type type = null;
                    if (allTypes.Count != 0)
                    {
                        type = allTypes.FirstOrDefault(type1 => type1.Name == typeName);
                    }
                    Resource resource;
                    if (type != null)
                    {
                        resource = (Resource)Activator.CreateInstance(type, xml);
                    }
                    else
                    {
                        resource = new Resource(xml);
                    }
                    if (currentItem.FilePath.EndsWith(".xml"))
                    {
                        _convertToBiteExtension.Add(currentItem.FilePath);
                        resource.FilePath = currentItem.FilePath.Replace(".xml", ".bite");
                    }
                    else
                    {
                        resource.FilePath = currentItem.FilePath;
                    }
                    xml = _resourceUpgrader.UpgradeResource(xml, Assembly.GetExecutingAssembly().GetName().Version, a =>
                    {
                        var fileManager = new TxFileManager();
                        using (TransactionScope tx = new TransactionScope())
                        {
                            try
                            {
                                var updateXml = a.ToStringBuilder();
                                var signedXml = HostSecurityProvider.Instance.SignXml(updateXml);
                                signedXml.WriteToFile(currentItem.FilePath, Encoding.UTF8, fileManager);
                                tx.Complete();
                            }
                            catch
                            {
                                try
                                {
                                    Transaction.Current.Rollback();
                                }
                                catch (Exception err)
                                {
                                    Dev2Logger.Error(err, GlobalConstants.WarewolfError);
                                }
                                throw;
                            }
                        }
                    });
                    if (resource.IsUpgraded)
                    {
                        // Must close the source stream first and then add a new target stream
                        // otherwise the file will be remain locked
                        currentItem.FileStream.Close();

                        xml = resource.UpgradeXml(xml, resource);

                        var updateXml   = xml.ToStringBuilder();
                        var signedXml   = HostSecurityProvider.Instance.SignXml(updateXml);
                        var fileManager = new TxFileManager();
                        using (TransactionScope tx = new TransactionScope())
                        {
                            try
                            {
                                signedXml.WriteToFile(currentItem.FilePath, Encoding.UTF8, fileManager);
                                tx.Complete();
                            }
                            catch
                            {
                                Transaction.Current.Rollback();
                                throw;
                            }
                        }
                    }

                    lock (_addLock)
                    {
                        AddResource(resource, currentItem.FilePath);
                    }
                }
                else
                {
                    Dev2Logger.Debug(string.Format("'{0}' wasn't loaded because it isn't signed or has modified since it was signed.", currentItem.FilePath), GlobalConstants.WarewolfDebug);
                }
            });
        }
Beispiel #13
0
 /// <summary>
 /// Gets the installer to use to upgrade game specific values.
 /// </summary>
 /// <param name="p_modMod">The mod being upgraded.</param>
 /// <param name="p_ilgInstallLog">The install log to use to log the installation of the game specific values.</param>
 /// <param name="p_tfmFileManager">The transactional file manager to use to interact with the file system.</param>
 /// <returns>The installer to use to manage game specific values, or <c>null</c> if the game mode does not
 /// install any game specific values.</returns>
 /// <param name="p_futFileUtility">The file utility class.</param>
 /// <param name="p_dlgOverwriteConfirmationDelegate">The method to call in order to confirm an overwrite.</param>
 public override IGameSpecificValueInstaller GetGameSpecificValueUpgradeInstaller(IMod p_modMod, IInstallLog p_ilgInstallLog, TxFileManager p_tfmFileManager, FileUtil p_futFileUtility, ConfirmItemOverwriteDelegate p_dlgOverwriteConfirmationDelegate)
 {
     return(new GamebryoGameSpecificValueInstaller(p_modMod, GameModeEnvironmentInfo, p_ilgInstallLog, p_tfmFileManager, p_futFileUtility, p_dlgOverwriteConfirmationDelegate));
 }
        public void BuildCatalogFromWorkspace(string workspacePath, params string[] folders)
        {
            if (string.IsNullOrEmpty(workspacePath))
            {
                throw new ArgumentNullException("workspacePath");
            }
            if (folders == null)
            {
                throw new ArgumentNullException("folders");
            }

            if (folders.Length == 0 || !Directory.Exists(workspacePath))
            {
                return;
            }

            var streams = new List <ResourceBuilderTO>();

            try
            {
                foreach (var path in folders.Where(f => !string.IsNullOrEmpty(f) && !f.EndsWith("VersionControl")).Select(f => Path.Combine(workspacePath, f)))
                {
                    if (!Directory.Exists(path))
                    {
                        continue;
                    }

                    var files = Directory.GetFiles(path, "*.xml");
                    foreach (var file in files)
                    {
                        FileAttributes fa = File.GetAttributes(file);

                        if ((fa & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                        {
                            Dev2Logger.Log.Info("Removed READONLY Flag from [ " + file + " ]");
                            File.SetAttributes(file, FileAttributes.Normal);
                        }

                        // Use the FileStream class, which has an option that causes asynchronous I/O to occur at the operating system level.
                        // In many cases, this will avoid blocking a ThreadPool thread.
                        var sourceStream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096, true);
                        streams.Add(new ResourceBuilderTO {
                            FilePath = file, FileStream = sourceStream
                        });
                    }
                }

                // Use the parallel task library to process file system ;)
                streams.ForEach(currentItem =>
                {
                    XElement xml = null;

                    try
                    {
                        xml = XElement.Load(currentItem.FileStream);
                    }
                    catch (Exception e)
                    {
                        Dev2Logger.Log.Error("Resource [ " + currentItem.FilePath + " ] caused " + e.Message);
                    }

                    StringBuilder result = xml.ToStringBuilder();

                    var isValid = xml != null && HostSecurityProvider.Instance.VerifyXml(result);
                    if (isValid)
                    {
                        var resource = new Resource(xml)
                        {
                            FilePath = currentItem.FilePath
                        };

                        //2013.08.26: Prevent duplicate unassigned folder in save dialog and studio explorer tree by interpreting 'unassigned' as blank
                        if (resource.ResourcePath.ToUpper() == "UNASSIGNED")
                        {
                            resource.ResourcePath = string.Empty;
                            // DON'T FORCE A SAVE HERE - EVER!!!!
                        }
                        xml = _resourceUpgrader.UpgradeResource(xml, Assembly.GetExecutingAssembly().GetName().Version, (a =>
                        {
                            var fileManager = new TxFileManager();
                            using (TransactionScope tx = new TransactionScope())
                            {
                                try
                                {
                                    StringBuilder updateXml = a.ToStringBuilder();
                                    var signedXml = HostSecurityProvider.Instance.SignXml(updateXml);

                                    signedXml.WriteToFile(currentItem.FilePath, Encoding.UTF8, fileManager);
                                    tx.Complete();
                                }
                                catch
                                {
                                    try
                                    {
                                        Transaction.Current.Rollback();
                                    }
                                    catch (Exception err)
                                    {
                                        Dev2Logger.Log.Error(err);
                                    }
                                    throw;
                                }
                            }
                        }


                                                                                                                         ));
                        if (resource.IsUpgraded)
                        {
                            // Must close the source stream first and then add a new target stream
                            // otherwise the file will be remain locked
                            currentItem.FileStream.Close();

                            xml = resource.UpgradeXml(xml, resource);

                            StringBuilder updateXml = xml.ToStringBuilder();
                            var signedXml           = HostSecurityProvider.Instance.SignXml(updateXml);
                            var fileManager         = new TxFileManager();
                            using (TransactionScope tx = new TransactionScope())
                            {
                                try
                                {
                                    signedXml.WriteToFile(currentItem.FilePath, Encoding.UTF8, fileManager);
                                    tx.Complete();
                                }
                                catch
                                {
                                    Transaction.Current.Rollback();
                                    throw;
                                }
                            }
                        }
                        if (resource.VersionInfo == null)
                        {
                        }

                        lock (_addLock)
                        {
                            AddResource(resource, currentItem.FilePath);
                        }
                    }
                    else
                    {
                        Dev2Logger.Log.Debug(string.Format("'{0}' wasn't loaded because it isn't signed or has modified since it was signed.", currentItem.FilePath));
                    }
                });
            }
            finally
            {
                // Close all FileStream instances in a finally block after the tasks are complete.
                // If each FileStream was instead created in a using statement, the FileStream
                // might be disposed of before the task was complete
                foreach (var stream in streams)
                {
                    stream.FileStream.Close();
                }
            }
        }
 /// <summary>
 /// Gets the installer to use to upgrade game specific values.
 /// </summary>
 /// <param name="p_modMod">The mod being upgraded.</param>
 /// <param name="p_ilgInstallLog">The install log to use to log the installation of the game specific values.</param>
 /// <param name="p_tfmFileManager">The transactional file manager to use to interact with the file system.</param>
 /// <returns>The installer to use to manage game specific values, or <c>null</c> if the game mode does not
 /// install any game specific values.</returns>
 /// <param name="p_futFileUtility">The file utility class.</param>
 /// <param name="p_dlgOverwriteConfirmationDelegate">The method to call in order to confirm an overwrite.</param>
 public override IGameSpecificValueInstaller GetGameSpecificValueUpgradeInstaller(IMod p_modMod, IInstallLog p_ilgInstallLog, TxFileManager p_tfmFileManager, FileUtil p_futFileUtility, ConfirmItemOverwriteDelegate p_dlgOverwriteConfirmationDelegate)
 {
     return(null);
 }
        private void PerformSaveResult(out ResourceCatalogResult saveResult, Guid workspaceID, IResource resource, StringBuilder contents, bool overwriteExisting, string savedPath)
        {
            var fileManager = new TxFileManager();

            using (TransactionScope tx = new TransactionScope())
            {
                try
                {
                    var resources   = _resourceCatalog.GetResources(workspaceID);
                    var conflicting = resources.FirstOrDefault(r => resource.ResourceID != r.ResourceID && r.GetResourcePath(workspaceID) != null && r.GetResourcePath(workspaceID).Equals(savedPath + "\\" + resource.ResourceName, StringComparison.InvariantCultureIgnoreCase) && r.ResourceName.Equals(resource.ResourceName, StringComparison.InvariantCultureIgnoreCase));
                    if (conflicting != null && !conflicting.IsNewResource || conflicting != null && !overwriteExisting)
                    {
                        saveResult = ResourceCatalogResultBuilder.CreateDuplicateMatchResult(string.Format(ErrorResource.TypeConflict, conflicting.ResourceType));
                        return;
                    }
                    var res = resources.FirstOrDefault(p => p.ResourceID == resource.ResourceID);
                    if (res != null)                                   //Found Existing resource
                    {
                        if (res.ResourceName != resource.ResourceName) // Renamed while open
                        {
                            var resourceXml = contents.ToXElement();
                            resourceXml.SetAttributeValue("Name", res.ResourceName);
                            resourceXml.SetElementValue("DisplayName", res.ResourceName);
                            var actionElement = resourceXml.Element("Action");
                            var xamlElement   = actionElement?.Element("XamlDefinition");
                            if (xamlElement != null)
                            {
                                var xamlContent = xamlElement.Value;
                                xamlElement.Value = xamlContent.
                                                    Replace("x:Class=\"" + resource.ResourceName + "\"", "x:Class=\"" + res.ResourceName + "\"")
                                                    .Replace("Flowchart DisplayName=\"" + resource.ResourceName + "\"", "Flowchart DisplayName=\"" + res.ResourceName + "\"");
                            }
                            resource.ResourceName = res.ResourceName;
                            contents = resourceXml.ToStringBuilder();
                        }
                    }
                    var directoryName = SetResourceFilePath(workspaceID, resource, ref savedPath);

                    #region Save to disk

                    var xml = SaveToDisk(resource, contents, directoryName, fileManager);

                    #endregion

                    #region Add to catalog

                    var updated = AddToCatalog(resource, resources, fileManager, xml);

                    #endregion
                    Dev2Logger.Debug($"Removing Execution Plan for {resource.ResourceID} for workspace {workspaceID}");
                    ((ResourceCatalog)_resourceCatalog).RemoveFromResourceActivityCache(workspaceID, resource);
                    Dev2Logger.Debug($"Removed Execution Plan for {resource.ResourceID} for workspace {workspaceID}");
                    Dev2Logger.Debug($"Adding Execution Plan for {resource.ResourceID} for workspace {workspaceID}");
                    ((ResourceCatalog)_resourceCatalog).Parse(workspaceID, resource.ResourceID);
                    Dev2Logger.Debug($"Added Execution Plan for {resource.ResourceID} for workspace {workspaceID}");
                    tx.Complete();
                    saveResult = ResourceCatalogResultBuilder.CreateSuccessResult($"{(updated ? "Updated" : "Added")} {resource.ResourceType} '{resource.ResourceName}'");
                }
                catch (Exception)
                {
                    Transaction.Current.Rollback();
                    throw;
                }
            }
        }
Beispiel #17
0
        // Save group
        private void cmdSave_Click(object sender, EventArgs e)
        {
            resetSelection();

            //List <Directory> directories =

            if (txtGroupName.Text == "Name the new group...") // Verify category name
            {
                lblErrorTitle.Text    = "Must select a name";
                lblErrorTitle.Visible = true;
            }
            else if (IsNew && Directory.Exists(@MainPath.path + @"\config\" + txtGroupName.Text) ||
                     !IsNew && Category.Name != txtGroupName.Text && Directory.Exists(@MainPath.path + @"\config\" + txtGroupName.Text))
            {
                lblErrorTitle.Text    = "There is already a group with that name";
                lblErrorTitle.Visible = true;
            }
            else if (!new Regex("^[0-9a-zA-Z \b]+$").IsMatch(txtGroupName.Text))
            {
                lblErrorTitle.Text    = "Name must not have any special characters";
                lblErrorTitle.Visible = true;
            }
            else if (cmdAddGroupIcon.BackgroundImage ==
                     global::client.Properties.Resources.AddWhite) // Verify icon
            {
                lblErrorIcon.Text    = "Must select group icon";
                lblErrorIcon.Visible = true;
            }
            else if (Category.ShortcutList.Count == 0) // Verify shortcuts
            {
                lblErrorShortcut.Text    = "Must select at least one shortcut";
                lblErrorShortcut.Visible = true;
            }
            else
            {
                try
                {
                    foreach (ProgramShortcut shortcutModifiedItem in shortcutChanged)
                    {
                        if (!Directory.Exists(shortcutModifiedItem.WorkingDirectory))
                        {
                            shortcutModifiedItem.WorkingDirectory = getProperDirectory(shortcutModifiedItem.FilePath);
                        }
                    }


                    if (!IsNew)
                    {
                        //
                        // Delete old config
                        //
                        string configPath   = @MainPath.path + @"\config\" + Category.Name;
                        string shortcutPath = @MainPath.path + @"\Shortcuts\" + Regex.Replace(Category.Name, @"(_)+", " ") + ".lnk";

                        try
                        {
                            IFileManager fm = new TxFileManager();
                            using (TransactionScope scope1 = new TransactionScope())
                            {
                                fm.DeleteDirectory(configPath);
                                fm.Delete(shortcutPath);
                                scope1.Complete();
                            }
                        } catch (Exception)
                        {
                            MessageBox.Show("Please close all programs used within the taskbar group in order to save!");
                            return;
                        }
                    }
                    //
                    // Creating new config
                    //
                    //int width = int.Parse(lblNum.Text);

                    Category.Width = int.Parse(lblNum.Text);

                    //Category category = new Category(txtGroupName.Text, Category.ShortcutList, width, System.Drawing.ColorTranslator.ToHtml(CategoryColor), Category.Opacity); // Instantiate category

                    // Normalize string so it can be used in path; remove spaces
                    Category.Name = Regex.Replace(txtGroupName.Text, @"\s+", "_");

                    Category.CreateConfig(cmdAddGroupIcon.BackgroundImage);            // Creating group config files
                    Client.LoadCategory(Path.GetFullPath(@"config\" + Category.Name)); // Loading visuals

                    this.Dispose();
                    Client.Reload();
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.Message);
                }

                Client.Reset();
            }
        }
Beispiel #18
0
 /// <summary>
 /// A simple constructor that initializes the object with its dependencies.
 /// </summary>
 /// <param name="p_modMod">The mod being installed.</param>
 /// <param name="p_ilgInstallLog">The install log to use to log file installations.</param>
 /// <param name="p_tfmFileManager">The transactional file manager to use to interact with the file system.</param>
 /// <param name="p_dlgOverwriteConfirmationDelegate">The method to call in order to confirm an overwrite.</param>
 public IniInstaller(IMod p_modMod, IInstallLog p_ilgInstallLog, IVirtualModActivator p_ivaVirtualModActivator, TxFileManager p_tfmFileManager, ConfirmItemOverwriteDelegate p_dlgOverwriteConfirmationDelegate)
 {
     TouchedFiles                       = new Set <string>(StringComparer.OrdinalIgnoreCase);
     Mod                                = p_modMod;
     InstallLog                         = p_ilgInstallLog;
     VirtualModActivator                = p_ivaVirtualModActivator;
     TransactionalFileManager           = p_tfmFileManager;
     m_dlgOverwriteConfirmationDelegate = p_dlgOverwriteConfirmationDelegate ?? ((s, b, m) => OverwriteResult.No);
 }