internal static string GetRootStyleFilename(string style_xml_filename)
        {
            string parent_filename;
            string parent_url;

            if (IsDependentStyle(style_xml_filename, out parent_filename, out parent_url))
            {
                // Check that we have the dependent style - if we don't prompt to download it
                string full_parent_filename = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(style_xml_filename), parent_filename));
                if (!File.Exists(full_parent_filename))
                {
                    string message = String.Format(
                        "Can't find parent style for this dependent style" +
                        "\n\n" +
                        "Your style depends on a parent style named {0}, which needs to be saved in the same directory.\n\n" +
                        "It appears to be available from {1}.\n" +
                        "Shall we try to download it automatically?  If you choose NO, Qiqqa will open the website for you so you can download it manually.",
                        parent_filename, parent_url
                        );

                    if (MessageBoxes.AskQuestion(message))
                    {
                        try
                        {
                            using (MemoryStream ms = UrlDownloader.DownloadWithBlocking(parent_url))
                            {
                                File.WriteAllBytes(full_parent_filename, ms.ToArray());
                            }
                        }
                        catch (UnauthorizedAccessException ex)
                        {
                            Logging.Error(ex, "You don't seem to have permission to write the new style to the directory '{0}'.\nPlease copy the original style file '{1}' to a folder where you can write (perhaps alongside your Word document), and try again.", full_parent_filename, style_xml_filename);
                            MessageBoxes.Warn("You don't seem to have permission to write the new style to the directory '{0}'.\nPlease copy the original style file '{1}' to a folder where you can write (perhaps alongside your Word document), and try again.", full_parent_filename, style_xml_filename);
                        }
                    }
                    else
                    {
                        MainWindowServiceDispatcher.Instance.OpenUrlInBrowser(parent_url, true);
                    }
                }

                // Check again if the parent file exists, and if it does, recurse the dependency check
                if (File.Exists(full_parent_filename))
                {
                    return(GetRootStyleFilename(full_parent_filename));
                }
                else
                {
                    // We need the parent style, but haven't managed to download it, so return nothing...
                    return(null);
                }
            }
            else // Not a dependent style, so use this filename
            {
                return(style_xml_filename);
            }
        }
Exemplo n.º 2
0
        private async Task InstallSteamWorkshopItems()
        {
            //var currentLib = "";
            SteamGame currentSteamGame = null;

            StoreHandler.Instance.SteamHandler.Games.Where(g => g.Game == GameInfo.Game).Do(s => currentSteamGame = (SteamGame)s);

            /*SteamHandler.Instance.InstallFolders.Where(f => f.Contains(currentSteamGame.InstallDir)).Do(s => currentLib = s);
             *
             * var downloadFolder = Path.Combine(currentLib, "workshop", "downloads", currentSteamGame.AppId.ToString());
             * var contentFolder = Path.Combine(currentLib, "workshop", "content", currentSteamGame.AppId.ToString());
             */
            if (!ModList.Directives.Any(s => s is SteamMeta))
            {
                return;
            }

            var result = await Utils.Log(new YesNoIntervention(
                                             "The ModList you are installing requires Steam Workshop items to exist. " +
                                             "You can check the Workshop Items in the manifest of this ModList. Wabbajack can start Steam for you " +
                                             "and download the Items automatically. Do you want to proceed with this step?",
                                             "Download Steam Workshop Items?")).Task;

            if (result != ConfirmationIntervention.Choice.Continue)
            {
                return;
            }

            await ModList.Directives.OfType <SteamMeta>()
            .PMap(Queue, item =>
            {
                Status("Extracting Steam meta file to temp folder");
                var path = Path.Combine(DownloadFolder, $"steamWorkshopItem_{item.ItemID}.meta");
                if (!File.Exists(path))
                {
                    File.WriteAllBytes(path, LoadBytesFromPath(item.SourceDataID));
                }

                Status("Downloading Steam Workshop Item through steam cmd");

                var p = new Process
                {
                    StartInfo = new ProcessStartInfo
                    {
                        FileName       = Path.Combine(StoreHandler.Instance.SteamHandler.SteamPath, "steam.exe"),
                        CreateNoWindow = true,
                        Arguments      = $"console +workshop_download_item {currentSteamGame.ID} {currentSteamGame.ID}"
                    }
                };

                p.Start();
            });
        }
Exemplo n.º 3
0
        public static void ToCERAS <T>(this T obj, string filename, ref SerializerConfig config)
        {
            var ceras = new CerasSerializer(config);

            byte[] buffer = null;
            ceras.Serialize(obj, ref buffer);
            using (var m1 = new MemoryStream(buffer))
                using (var m2 = new MemoryStream())
                {
                    BZip2.Compress(m1, m2, false, 9);
                    m2.Seek(0, SeekOrigin.Begin);
                    File.WriteAllBytes(filename, m2.ToArray());
                }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds a file to the given mod with a given path in the mod. Fills it with random data unless
        /// random_fill == 0;
        /// </summary>
        /// <param name="mod_name"></param>
        /// <param name="path"></param>
        /// <param name="random_fill"></param>
        /// <returns></returns>
        public string AddModFile(string mod_name, string path, int random_fill = 128)
        {
            byte[] bytes = new byte[0];
            if (random_fill != 0)
            {
                bytes = new byte[random_fill];
                RNG.NextBytes(bytes);
            }

            var full_path = Path.Combine(ModsFolder, mod_name, path);

            Directory.CreateDirectory(Path.GetDirectoryName(full_path));
            File.WriteAllBytes(full_path, bytes);
            return(full_path);
        }
Exemplo n.º 5
0
        private async Task InstallIncludedFiles()
        {
            Info("Writing inline files");
            await ModList.Directives.OfType <InlineFile>()
            .PMap(Queue, directive =>
            {
                if (directive.To.EndsWith(Consts.MetaFileExtension))
                {
                    return;
                }

                Info($"Writing included file {directive.To}");
                var outPath = Path.Combine(OutputFolder, directive.To);
                if (File.Exists(outPath))
                {
                    File.Delete(outPath);
                }
                File.WriteAllBytes(outPath, LoadBytesFromPath(directive.SourceDataID));
            });
        }
        internal static void Install(BundleLibraryManifest manifest, byte[] library_bundle_binary)
        {
            string temp_filename = Path.GetTempFileName();

            try
            {
                File.WriteAllBytes(temp_filename, library_bundle_binary);
                Install(manifest, temp_filename);
            }
            finally
            {
                try
                {
                    File.Delete(temp_filename);
                }
                catch (Exception ex)
                {
                    Logging.Error(ex, "There was a problem deleting the temporary library bundle file.");
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Creates a new file, writes the specified byte array to the file, and then closes the file.
 /// If the target file already exists, it is overwritten.
 /// </summary>
 /// <param name="path">The file to write to.</param>
 /// <param name="bytes">The bytes 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"><paramref name="path"/> is <see langword="null"/> or contents is empty.</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">
 /// path specified a file that is read-only.
 /// -or-
 /// This operation is not supported on the current platform.
 /// -or-
 /// 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>
 /// Given a byte array and a file path, this method opens the specified file, writes the contents of the byte array to the file, and then closes the file.
 /// </remarks>
 public override void WriteAllBytes(string path, byte[] bytes)
 {
     AfsFile.WriteAllBytes(path, bytes);
 }