Exemplo n.º 1
0
 public void Init()
 {
     FilePathHelper = new FilePathHelper(videoPath, catalogPath);
     ThumbCreator = new MediaToolkitExtractor(filePathHelper: FilePathHelper, silentMode: false);
     if (File.Exists(ThumbCreator.OutputImagePath))
         File.Delete(ThumbCreator.OutputImagePath);
 }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="file"></param>
        /// <param name="path">Location to save file on hard drive.</param>
        /// <param name="maxSize">Maximum allowed file size in bytes.</param>
        /// <param name="fileExtensions">Allowed file extensions (separate with commas and must be valid image formats).</param>
        /// <param name="width">Resize image width.</param>
        /// <param name="height">resize image height.</param>
        /// <returns></returns>
        public static async Task UploadPicture(IFormFile file, string path, int maxSize = 0, string fileExtensions = "", int width = 0, int height = 0)
        {
            //fileExtensions = String.IsNullOrEmpty(fileExtensions) ? Extensions[FileType.Picture] : fileExtensions;

            ValidateOrSetFileExtensionsListForFileType(ref fileExtensions, FileType.Picture);

            string fileExtension = Path.GetExtension(file.FileName);

            if (fileExtensions.Contains(fileExtension))
            {
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    var    mime     = GetMimeType(stream).Split("/");
                    string fileType = mime[0];
                    if (fileType == "image")
                    {
                        //await UploadFile(file, stream, path, maxSize);
                        if (file.Length > 0 && (file.Length < maxSize || maxSize == -1))
                        {
                            try
                            {
                                if (width > 0 && height > 0)
                                {
                                    await file.CopyToAsync(ThumbnailMaker.CreateThumbnailFromStream(stream, width, height, path));
                                }
                                else
                                {
                                    await file.CopyToAsync(stream);
                                }
                            }
                            catch (Exception exception)
                            {
                                throw new Exception("", exception);
                            }
                        }
                        throw new Exception("Invalid file size");
                    }
                    throw new Exception("Invalid picture format");
                }
            }
            throw new Exception("Invalid picture file extension");
        }
Exemplo n.º 3
0
    public static void ExportBundle(string source)
    {
        string dest = Path.Combine(ModManager.GetModsfolderPath(), $"modfile_{Path.GetFileName(source)}");

        Debug.Log($"Exporting Mod: Source: \"{source}\", Target: \"{dest}\"");

        // Get Files and convert absolute paths to relative paths (required by the buildmap)
        string[] absolute_files = Directory.GetFiles(source).Where(name => !name.EndsWith(".meta") && !name.EndsWith(".cs")).ToArray();
        string[] files          = new string[absolute_files.Length];

        if (files.Length > 0)
        {
            int index = absolute_files[0].IndexOf("Assets");
            for (int i = 0; i < files.Length; i++)
            {
                files[i] = absolute_files[i].Substring(index);
            }
        }

        if (!CheckHasHolder(files))
        {
            throw new System.Exception($"Failed to export \"{Path.GetDirectoryName(source)}\". Make sure you have an appropriate holder included!");
        }

        // Prepare Bundle
        AssetBundleBuild[] build_map = new AssetBundleBuild[1];
        build_map[0].assetNames = files;

        // Build Folder / Bundle
        Directory.CreateDirectory(dest);
        foreach (var target in new Dictionary <OperatingSystemFamily, BuildTarget> {
            { OperatingSystemFamily.Windows, BuildTarget.StandaloneWindows64 }, { OperatingSystemFamily.Linux, BuildTarget.StandaloneLinux64 }, { OperatingSystemFamily.MacOSX, BuildTarget.StandaloneOSX }
        })
        {
            build_map[0].assetBundleName = $"{Path.GetFileName(source)}_{target.Key}";
            BuildPipeline.BuildAssetBundles(dest, build_map, BuildAssetBundleOptions.None, target.Value);
        }

        // Clean out manifest files and bundle holder
        try {
            if (Directory.GetFiles(dest).Count() > 10)  // FAILSAFE
            {
                throw new System.ArgumentException($"failsafe triggered: too many files found in mod folder! Skipping deletion of unneeded files!");
            }

            File.Delete(Path.Combine(dest, Path.GetFileName(dest)));
            foreach (var manifest in Directory.GetFiles(dest, "*.manifest", SearchOption.TopDirectoryOnly))
            {
                File.Delete(Path.Combine(dest, manifest));
            }
        } catch (System.UnauthorizedAccessException) {
            Debug.LogWarning("Unauthorized to delete obsolete files in the exported mod. These files are not needed and don't need to be removed manually.");
        } catch (System.ArgumentException e) {
            Debug.LogError(e);
        }

        // Make Thumbnail
        GameObject thumbnailMakerPrefab = UnityEditor.AssetDatabase.LoadAssetAtPath <GameObject>("Assets/ThumbnailMaker.prefab");

        if (thumbnailMakerPrefab)
        {
            Mod mod = ModImporter.ImportModNow(dest, true);

            string lastScene      = EditorSceneManager.GetActiveScene().path;
            int    lastBuildIndex = EditorSceneManager.GetActiveScene().buildIndex;

            // Create scene
            Scene          thumbnailScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
            ThumbnailMaker thumbnailMaker = Instantiate(thumbnailMakerPrefab).GetComponent <ThumbnailMaker>();

            File.WriteAllBytes(mod.GetThumbnailPath(), thumbnailMaker.CreateThumbnail(mod).EncodeToJPG(90));
            // Cleanup
            if (lastBuildIndex >= 0)
            {
                EditorSceneManager.OpenScene(lastScene, OpenSceneMode.Single);
            }
            else
            {
                EditorSceneManager.OpenScene(EditorSceneManager.GetSceneByBuildIndex(0).path);
            }
        }

        Debug.Log($"Export Completed. Name: \"{Path.GetFileName(source)}\" with {files.Length} files");
    }