Esempio n. 1
0
        public async Task ModifiedIniFilesArePatchedAgainstFileWithSameName()
        {
            var profile = utils.AddProfile();
            var mod     = utils.AddMod();
            var ini     = utils.AddModFile(mod, @"foo.ini", 10);
            var meta    = utils.AddModFile(mod, "meta.ini");

            utils.Configure();


            var archive = utils.AddManualDownload(
                new Dictionary <string, byte[]> {
                { "/baz/foo.ini", File.ReadAllBytes(ini) }
            });

            File.WriteAllLines(meta, new[]
            {
                "[General]",
                $"installationFile={archive}",
            });

            // Modify after creating mod archive in the downloads folder
            File.WriteAllText(ini, "Wabbajack, Wabbajack, Wabbajack!");

            var modlist = await CompileAndInstall(profile);

            var directive = modlist.Directives.Where(m => m.To == $"mods\\{mod}\\foo.ini").FirstOrDefault();

            Assert.IsNotNull(directive);
            Assert.IsInstanceOfType(directive, typeof(PatchedFromArchive));
        }
Esempio n. 2
0
        public string AddManualDownload(Dictionary <string, byte[]> contents)
        {
            var name = RandomName() + ".zip";

            using (FileStream fs = new FileStream(Path.Combine(DownloadsFolder, name), FileMode.Create))
                using (ZipArchive archive = new ZipArchive(fs, ZipArchiveMode.Create))
                {
                    contents.Do(kv =>
                    {
                        var entry = archive.CreateEntry(kv.Key);
                        using (var os = entry.Open())
                            os.Write(kv.Value, 0, kv.Value.Length);
                    });
                }

            File.WriteAllLines(Path.Combine(DownloadsFolder, name + ".meta"),

                               new string[]
            {
                "[General]",
                "manualURL=<TESTING>"
            });

            return(name);
        }
Esempio n. 3
0
        public async Task SetScreenSizeTest()
        {
            var profile = utils.AddProfile();
            var mod     = utils.AddMod("dummy");

            utils.Configure();
            File.WriteAllLines(Path.Combine(utils.MO2Folder, "profiles", profile, "somegameprefs.ini"),
                               new List <string>
            {
                // Beth inis are messy, let's make ours just as messy to catch some parse failures
                "[Display]",
                "foo=4",
                "[Display]",
                "STestFile=f",
                "STestFile=",
                "iSize H=3",
                "iSize W=-200",
                "[Display]",
                "foo=4"
            });

            var modlist = await CompileAndInstall(profile);

            var ini = Path.Combine(utils.InstallFolder, "profiles", profile, "somegameprefs.ini").LoadIniFile();

            Assert.AreEqual(System.Windows.SystemParameters.PrimaryScreenHeight.ToString(), ini?.Display?["iSize H"]);
            Assert.AreEqual(System.Windows.SystemParameters.PrimaryScreenWidth.ToString(), ini?.Display?["iSize W"]);
        }
Esempio n. 4
0
        public static void SaveDesktop()
        {
            List <string> restore_settings = new List <string>();

            // Get the remembrances
            List <FrameworkElement> framework_elements = MainWindowServiceDispatcher.Instance.MainWindow.DockingManager.GetAllFrameworkElements();

            foreach (FrameworkElement framework_element in framework_elements)
            {
                {
                    LibraryControl library_control = framework_element as LibraryControl;
                    if (null != library_control)
                    {
                        Logging.Info("Remembering a library control {0}", library_control.Library.WebLibraryDetail.Id);
                        restore_settings.Add(String.Format("PDF_LIBRARY,{0}", library_control.Library.WebLibraryDetail.Id));
                    }
                }

                {
                    PDFReadingControl pdf_reading_control = framework_element as PDFReadingControl;
                    if (null != pdf_reading_control)
                    {
                        Logging.Info("Remembering a PDF reader {0}", pdf_reading_control.PDFRendererControlStats.pdf_document.Fingerprint);
                        restore_settings.Add(String.Format("PDF_DOCUMENT,{0},{1}", pdf_reading_control.PDFRendererControlStats.pdf_document.Library.WebLibraryDetail.Id, pdf_reading_control.PDFRendererControlStats.pdf_document.Fingerprint));
                    }
                }
            }

            // Store the remembrances
            File.WriteAllLines(Filename, restore_settings);
        }
 private void SaveSearchHistory()
 {
     try
     {
         File.WriteAllLines(SearchHistoryFilename, SearchHistory);
     }
     catch (Exception ex)
     {
         Logging.Error(ex, "There was a problem saving the search history.");
     }
 }
Esempio n. 6
0
        public void Save(string filename)
        {
            List <string> lines = new List <string>();

            List <string> keys_sorted = new List <string>(Keys);

            keys_sorted.Sort();

            foreach (string key in keys_sorted)
            {
                lines.Add(key + LINE_SPLITTER + this[key]);
            }

            File.WriteAllLines(filename, lines.ToArray());
        }
Esempio n. 7
0
        public void Configure()
        {
            File.WriteAllLines(Path.Combine(MO2Folder, "ModOrganizer.ini"), new []
            {
                "[General]",
                $"gameName={GameName}",
                $"gamePath={GameFolder.Replace("\\", "\\\\")}",
            });

            Directory.CreateDirectory(DownloadsFolder);
            Directory.CreateDirectory(GameFolder);

            Profiles.Do(profile =>
            {
                File.WriteAllLines(Path.Combine(MO2Folder, "profiles", profile, "modlist.txt"),
                                   Mods.Select(s => $"+{s}").ToArray());
            });
        }
 public void Save()
 {
     // Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
     lock (tokens_lock)
     {
         // l1_clk.LockPerfTimerStop();
         if (!is_dirty)
         {
             return;
         }
         try
         {
             File.WriteAllLines(FILENAME, tokens.ToArray());
         }
         catch (Exception ex)
         {
             Logging.Warn(ex, "There was a problem saving {0}", FILENAME);
         }
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Creates a new file, writes the specified string array to the file by using the specified encoding, and then closes the file.
 /// </summary>
 /// <param name="path">The file to write to.</param>
 /// <param name="contents">The string array to write to the file.</param>
 /// <param name="encoding">An <see cref="Encoding"/> object that represents the character encoding applied to the string array.</param>
 /// <exception cref="ArgumentException"><paramref name="path"/> is a zero-length string, contains only white space, or contains one or more invalid characters as defined by <see cref="Path.GetInvalidPathChars"/>.</exception>
 /// <exception cref="ArgumentNullException">Either <paramref name="path"/> or <paramref name="contents"/> is <see langword="null"/>.</exception>
 /// <exception cref="PathTooLongException">
 /// The specified path, file name, or both exceed the system-defined maximum length.
 /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.
 /// </exception>
 /// <exception cref="DirectoryNotFoundException">The specified path is invalid (for example, it is on an unmapped drive).</exception>
 /// <exception cref="IOException">An I/O error occurred while opening the file.</exception>
 /// <exception cref="UnauthorizedAccessException">
 /// <paramref name="path"/> specified a file that is read-only.
 /// -or-
 /// This operation is not supported on the current platform.
 /// -or-
 /// <paramref name="path"/> specified a directory.
 /// -or-
 /// The caller does not have the required permission.
 /// </exception>
 /// <exception cref="FileNotFoundException">The file specified in <paramref name="path"/> was not found.</exception>
 /// <exception cref="NotSupportedException"><paramref name="path"/> is in an invalid format.</exception>
 /// <exception cref="System.Security.SecurityException">The caller does not have the required permission.</exception>
 /// <remarks>
 /// <para>
 ///     If the target file already exists, it is overwritten.
 /// </para>
 /// <para>
 ///     Given a string array and a file path, this method opens the specified file, writes the string array to the file using the specified encoding,
 ///     and then closes the file.
 /// </para>
 /// </remarks>
 public override void WriteAllLines(string path, string[] contents, Encoding encoding)
 {
     AfsFile.WriteAllLines(path, contents, encoding);
 }
Esempio n. 10
0
 /// <summary>
 /// Creates a new file, writes the specified string array to the file by using the specified encoding, and then closes the file.
 /// </summary>
 /// <param name="path">The file to write to.</param>
 /// <param name="contents">The string array to write to the file.</param>
 /// <exception cref="ArgumentException"><paramref name="path"/> is a zero-length string, contains only white space, or contains one or more invalid characters as defined by <see cref="Path.GetInvalidPathChars"/>.</exception>
 /// <exception cref="ArgumentNullException">Either <paramref name="path"/> or <paramref name="contents"/> is <see langword="null"/>.</exception>
 /// <exception cref="PathTooLongException">
 /// The specified path, file name, or both exceed the system-defined maximum length.
 /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.
 /// </exception>
 /// <exception cref="DirectoryNotFoundException">The specified path is invalid (for example, it is on an unmapped drive).</exception>
 /// <exception cref="IOException">An I/O error occurred while opening the file.</exception>
 /// <exception cref="UnauthorizedAccessException">
 /// <paramref name="path"/> specified a file that is read-only.
 /// -or-
 /// This operation is not supported on the current platform.
 /// -or-
 /// <paramref name="path"/> specified a directory.
 /// -or-
 /// The caller does not have the required permission.
 /// </exception>
 /// <exception cref="FileNotFoundException">The file specified in <paramref name="path"/> was not found.</exception>
 /// <exception cref="NotSupportedException"><paramref name="path"/> is in an invalid format.</exception>
 /// <exception cref="System.Security.SecurityException">The caller does not have the required permission.</exception>
 /// <remarks>
 /// <para>
 ///     If the target file already exists, it is overwritten.
 /// </para>
 /// <para>
 ///     The default behavior of the WriteAllLines method is to write out data using UTF-8 encoding without a byte order mark (BOM). If it is necessary to include a UTF-8 identifier, such as a byte order mark, at the beginning of a file, use the <see cref="FileBase.WriteAllLines(string,string[],System.Text.Encoding)"/> method overload with <see cref="UTF8Encoding"/> encoding.
 /// </para>
 /// <para>
 ///     Given a string array and a file path, this method opens the specified file, writes the string array to the file using the specified encoding,
 ///     and then closes the file.
 /// </para>
 /// </remarks>
 public override void WriteAllLines(string path, string[] contents)
 {
     AfsFile.WriteAllLines(path, contents);
 }
Esempio n. 11
0
 /// <summary>
 /// Creates a new file by using the specified encoding, writes a collection of strings to the file, and then closes the file.
 /// </summary>
 /// <param name="path">The file to write to.</param>
 /// <param name="contents">The lines to write to the file.</param>
 /// <param name="encoding">The character encoding to use.</param>
 /// <exception cref="ArgumentException"><paramref name="path"/> is a zero-length string, contains only white space, or contains one or more invalid characters as defined by <see cref="Path.GetInvalidPathChars"/>.</exception>
 /// <exception cref="ArgumentNullException">Either <paramref name="path"/>, <paramref name="contents"/>, or <paramref name="encoding"/> is <see langword="null"/>.</exception>
 /// <exception cref="DirectoryNotFoundException">The specified path is invalid (for example, it is on an unmapped drive).</exception>
 /// <exception cref="FileNotFoundException">The file specified in <paramref name="path"/> was not found.</exception>
 /// <exception cref="IOException">An I/O error occurred while opening the file.</exception>
 /// <exception cref="PathTooLongException">
 /// The specified path, file name, or both exceed the system-defined maximum length.
 /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.
 /// </exception>
 /// <exception cref="NotSupportedException"><paramref name="path"/> is in an invalid format.</exception>
 /// <exception cref="System.Security.SecurityException">The caller does not have the required permission.</exception>
 /// <exception cref="UnauthorizedAccessException">
 /// <paramref name="path"/> specified a file that is read-only.
 /// -or-
 /// This operation is not supported on the current platform.
 /// -or-
 /// <paramref name="path"/> specified a directory.
 /// -or-
 /// The caller does not have the required permission.
 /// </exception>
 /// <remarks>
 /// <para>
 ///     If the target file already exists, it is overwritten.
 /// </para>
 /// <para>
 ///     You can use this method to create a file that contains the following:
 /// <list type="bullet">
 /// <item>
 /// <description>The results of a LINQ to Objects query on the lines of a file, as obtained by using the ReadLines method.</description>
 /// </item>
 /// <item>
 /// <description>The contents of a collection that implements an <see cref="IEnumerable{T}"/> of strings.</description>
 /// </item>
 /// </list>
 /// </para>
 /// </remarks>
 public override void WriteAllLines(string path, IEnumerable <string> contents, Encoding encoding)
 {
     AfsFile.WriteAllLines(path, contents, encoding);
 }