예제 #1
0
        private void LoadExternalMods()
        {
            int i = 0;

            string[]      terms         = { ".patch" };
            List <string> searchresults = ResourceUtil.directorySearchRecursive(Settings.Default.PatchPath, terms);

            if (searchresults != null)
            {
                foreach (string modpath in searchresults)
                {
                    if (!modpath.ContainsCI("debug") && !modpath.ContainsCI("currentbuild"))
                    {
                        AvailableMods.Add(new Mod(modpath));
                        i++;
                    }
                }
            }
            if (i > 0)
            {
                Trace.WriteLine(String.Format("Added {0} external mods", i));
            }
            else
            {
                Trace.WriteLine("No external mods found");
            }
        }
예제 #2
0
        //public static bool AuthenticateMod(Stream outStream)
        //{
        //    foreach (IPlugin i in Plugins)
        //    {
        //        if (i != null && i.Name != null && i.Name == "SharpTune Vin Authentication")
        //            return i.Run(outStream);
        //    }
        //    DialogResult res;
        //    res = MessageBox.Show("Auth Plugin not found! Download?", "Plugin Missing!", MessageBoxButtons.YesNo);
        //    if (res == DialogResult.Yes)
        //    {
        //        if (InstallAuth())
        //        {
        //            SharpTuner.LoadPlugins();
        //            return AuthenticateMod(outStream);
        //        }
        //    }
        //    return false;
        //}

        //private static Uri AuthDownloadUri = new Uri("http://sharptuning.com/wp-content/uploads/edd/2013/05/SharpTuneAuth.dll");
        //private static bool InstallAuth()
        //{
        //    try
        //    {
        //        using (WebClient webClient = new WebClient())
        //        {
        //            webClient.DownloadFile(AuthDownloadUri, Settings.Default.PluginPath + @"\SharpTuneAuth.dll");
        //            webClient.Dispose();
        //        }
        //        return true;
        //    }
        //    catch (Exception E)
        //    {
        //        Trace.WriteLine(E.Message);
        //        MessageBox.Show("Error downloading auth plugin!");
        //        return false;
        //    }
        //}


        /// <summary>
        /// Gets mods from embedded resources
        /// </summary>
        private void LoadResourceMods()
        {
            int i        = 0;
            var assembly = Assembly.GetExecutingAssembly();

            string[] resources = assembly.GetManifestResourceNames();
            foreach (string res in resources)
            {
                if (!res.ContainsCI(".patch"))
                {
                    continue;
                }
                Stream stream = assembly.GetManifestResourceStream(res);
                AvailableMods.Add(new Mod(stream, res));
                i++;
            }
            if (i > 0)
            {
                Trace.WriteLine(String.Format("Added {0} embedded mods", i));
            }
            else
            {
                Trace.WriteLine("No embedded mods found");
            }

            //int i = AvailableMods.Count;
            //ResourceSet ress = Resources.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true);
            //ResourceManager rm = SharpTune.Properties.Resources.ResourceManager;
            //foreach (DictionaryEntry r in ress)
            //{
            //    MemoryStream stream = new MemoryStream((byte[])rm.GetObject(r.Key.ToString()));
            //    //if (tempMod.TryCheckApplyMod(FilePath, FilePath + ".temp", 2, false))
            //    AvailableMods.Add(new Mod(stream, r.Key.ToString()));
            //}
        }
예제 #3
0
        public void AddLocalMod(string path)
        {
            Mod    m              = new Mod(string.Empty, Path.GetFileNameWithoutExtension(path), DateTime.Now, string.Empty, string.Empty, string.Empty, string.Empty, Guid.NewGuid().ToString("N"), string.Empty, true);
            string modZipPath     = zipPath + m.Slug + ".zip";
            string modExtractPath = Mod.InstallPath + m.Slug + "\\";

            File.Copy(path, modZipPath);
            UnpackMod(modZipPath, modExtractPath);
            AvailableMods.Add(m);
            UpdateSettings();
        }
예제 #4
0
        /// <summary>
        /// TODO FIX OR REMOVE THIS. Can't really embed mods as resources without source code anyway!!
        /// </summary>
        private static void LoadResourceMods()
        {
            int             i    = AvailableMods.Count;
            ResourceSet     ress = Resources.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true);
            ResourceManager rm   = SharpTune.Properties.Resources.ResourceManager;

            foreach (DictionaryEntry r in ress)
            {
                MemoryStream stream = new MemoryStream((byte[])rm.GetObject(r.Key.ToString()));
                //if (tempMod.TryCheckApplyMod(FilePath, FilePath + ".temp", 2, false))
                AvailableMods.Add(new Mod(stream, r.Key.ToString()));
            }
        }
예제 #5
0
        /// <summary>
        /// Uninstalls a game mod.
        /// </summary>
        public async Task Uninstall(Mod m)
        {
            string modPath    = AppDomain.CurrentDomain.BaseDirectory + "\\mods\\" + m.Slug;
            string backupPath = AppDomain.CurrentDomain.BaseDirectory + "\\backups\\" + m.Slug;

            Console.WriteLine("Uninstall Task");
            if (Directory.Exists(backupPath))
            {
                foreach (var f in Directory.GetFiles(modPath))
                {
                    string fileName = Path.GetFileName(f);
                    string from     = modPath + "\\" + fileName;
                    string destin   = settings.PSO2Dir + "\\" + fileName;
                    string backup   = backupPath + "\\" + fileName;

                    if (!File.Exists(backup))
                    {
                        continue;
                    }
                    // TODO: if backup file does not exists or not vanilla file, download patch from official site

                    var UninstallTask = new Helpers.FileCopy(backup, destin);
                    if (!await Task.Run(() => UninstallTask.StartCopy()))
                    {
                        // If error, download patch from official site
                        await Task.Run(() => Helpers.DownloadPatch(fileName, destin));
                    }
                }
                Directory.Delete(backupPath, true);
            }
            else
            {
                MessageBox.Show("The backup is missing or something... mod won't really uninstall, do a file check plz");
            }
            if (m.ToolInfo == null)
            {
                m.ToolInfo = "";
            }
            m.ToolInfo.Replace(Mod.ModBrokenMessage, "");
            InstalledMods.Remove(m);
            AvailableMods.Add(m);
            UpdateSettings();
        }
예제 #6
0
        private static void LoadExternalMods()
        {
            int i = AvailableMods.Count;

            string[]      terms         = { ".patch" };
            List <string> searchresults = ResourceUtil.directorySearchRecursive(Settings.Default.PatchPath, terms);

            if (searchresults == null)
            {
                Trace.WriteLine("No External Mods found");
            }
            else
            {
                foreach (string modpath in searchresults)
                {
                    if (!modpath.ContainsCI("debug") && !modpath.ContainsCI("currentbuild"))
                    {
                        AvailableMods.Add(new Mod(modpath));
                    }
                }
            }
        }
예제 #7
0
        /// <summary>
        /// From a provided REST API endpoint download a mod.
        /// </summary>
        public async Task DownloadMod(string url)
        {
            Downloading = true;
            string modZipPath;
            string modImagePath;
            string modExtractPath;
            string modString = string.Empty;

            using (WebClient wc = new WebClient()) {
                dynamic Data = new OnDownloadCompleteArgs();
                OnDownloadStart?.Invoke(this, Data);


                wc.DownloadProgressChanged += WCDownloadPercentChanged;
                try {
                    modString = await wc.DownloadStringTaskAsync(url);
                } catch (WebException ex) {
                    Data.ErrorMessage = ex.Message;
                    OnDownloadComplete?.Invoke(this, Data);
                    return;
                }
                JsonObject json = JsonObject.Parse(modString);
                // Let's make sure the slug doesn't have weird stuff.
                json["slug"] = string.Join(" ", json["slug"].Split(Path.GetInvalidFileNameChars().Concat(Path.GetInvalidPathChars()).ToArray()));
                if (json["compatible"] != "Yes")
                {
                    Data.ErrorMessage = Helpers._("Error.NotCompatible");
                    OnDownloadComplete?.Invoke(this, Data);
                    return;
                }
                m = new Mod(
                    json["id"],
                    json.ArrayObjects("title") [0]["rendered"],
                    DateTime.ParseExact(json["modified"].Replace("T", " "), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
                    json.ArrayObjects("content") [0]["rendered"],
                    json["author_name"],
                    url,
                    json["File"],
                    json["slug"],
                    json["slug"] + ".jpg"
                    );
                modZipPath     = zipPath + m.Slug + ".zip";
                modExtractPath = Mod.InstallPath + m.Slug + "\\";
                modImagePath   = Mod.ImagePath + m.Thumbnail;

                // Cleanup previous versions and files.
                Delete(m.Slug);
                if (File.Exists(modZipPath))
                {
                    File.Delete(modZipPath);
                }
                if (Directory.Exists(modExtractPath))
                {
                    Directory.Delete(modExtractPath, true);
                }
                if (File.Exists(modImagePath))
                {
                    File.Delete(modImagePath);
                }

                // And start downloading stuff.
                try {
                    await wc.DownloadFileTaskAsync(new System.Uri(json["image"]), modImagePath);
                } catch (WebException we) {
                    Data.ErrorMessage = we.Message;
                    OnDownloadComplete?.Invoke(this, Data);
                    return;
                }
                try {
                    await wc.DownloadFileTaskAsync(new System.Uri(m.File), modZipPath);
                } catch (WebException we) {
                    Data.ErrorMessage = we.Message;
                    OnDownloadComplete?.Invoke(this, Data);
                    return;
                }
                UnpackMod(modZipPath, modExtractPath);
                AvailableMods.Add(m);
                Data.Success = true;
                OnDownloadComplete?.Invoke(this, Data);
                UpdateSettings();
            }
            Downloading = false;
        }