Esempio n. 1
0
        public async Task <MMDPluginPackage> InstallPlugin(string zipPath)
        {
            return(await Task.Run(() =>
            {
                var hash = CreateSHA1Hash(zipPath);
                DownloadPluginData loadItem;

                if (DownloadPluginDic.TryGetValue(hash, out loadItem) == false)
                {
                    throw new ArgumentException("A hash matching the SHA1 of the zip file was not found.\n");
                }

                var packageData = new MMDPluginPackage
                {
                    Version = loadItem.LatestVersion
                };
                using (var zipArchive = ZipFile.OpenRead(zipPath))
                {
                    foreach (var entry in zipArchive.Entries)
                    {
                        var filename = entry.FullName.Replace('/', '\\');
                        if (string.IsNullOrEmpty(filename) || filename[filename.Length - 1] == '\\')
                        {
                            continue;
                        }
                        string path;
                        if (!loadItem.TryGetInstallDir(filename, out path))
                        {
                            continue;
                        }

                        path = Path.Combine(_installPath, path, Path.GetFileName(filename));
                        Directory.CreateDirectory(Directory.GetParent(path).FullName);
                        entry.ExtractToFile(path, true);

                        if (Path.GetExtension(path).ToLower() == ".dll")
                        {
                            packageData.InstalledDLL.Add(path);
                        }

                        if (loadItem.IsReadMeFile(filename))
                        {
                            packageData.ReadMeFilePath = path;
                        }
                    }
                }
                MMDInstalledPluginPackage[loadItem.Title] = packageData;
                File.WriteAllText(GetMMDPluginPackageJsonFilename(),
                                  JsonConvert.SerializeObject(MMDInstalledPluginPackage));
                RaisePropertyChanged(nameof(DownloadPluginDic));
                return packageData;
            }));
        }
Esempio n. 2
0
        public async Task LoadPluginData()
        {
            try
            {
                var mmdpluginPackageJsonText = File.ReadAllText(GetMMDPluginPackageJsonFilename());
                MMDInstalledPluginPackage =
                    JsonConvert.DeserializeObject <Dictionary <string, MMDPluginPackage> >(mmdpluginPackageJsonText);
            }
            catch (Exception)
            {
                MMDInstalledPluginPackage = new Dictionary <string, MMDPluginPackage>();
            }

            float mmdPluginVersion = -1;
            var   jsonData         = await GetPackageList();

            foreach (var item in jsonData)
            {
                MMDPluginPackage package = null;
                MMDInstalledPluginPackage.TryGetValue(item.Title, out package);
                if (string.IsNullOrEmpty(item.SHA1Hash))
                {
                    // TODO エラーログの追加
                    continue;
                }
                DownloadPluginDic.Add(item.SHA1Hash, new DownloadPluginData(item.InstallDir, item.Readme)
                {
                    Url           = item.URL,
                    LatestVersion = item.Version,
                    Title         = item.Title,
                });
                if (item.Title == "MMDPlugin")
                {
                    mmdPluginVersion = item.Version;
                }
            }
            RaisePropertyChanged(nameof(DownloadPluginDic));


            MMDPluginPackage mmdPluginPackage;

            if (MMDInstalledPluginPackage.TryGetValue("MMDPlugin", out mmdPluginPackage))
            {
                if (Math.Abs(mmdPluginPackage.Version - mmdPluginVersion) < 1e-5f)
                {
                    IsInstalledMMDPlugin = true;
                }
            }
        }