Ejemplo n.º 1
0
        private static void DoExportRelease(string packagePath, bool silent, bool includeSourceZipInPackage)
        {
            var packageDirectory = Path.GetDirectoryName(packagePath);

            Debug.Log("package path: " + packagePath);
            if (!silent)
            {
                ProgressUtility.DisplayProgressBar("Exporting Release Package", "Creating Unity Package...", 0);
            }

            var paths = new List <string>()
            {
                instance.documentationPath,
                Path.Combine(Paths.assets, "Ludiq/Assemblies")
            };

            foreach (var product in ProductContainer.products)
            {
                paths.Add(product.packagePath);
            }

            foreach (var plugin in PluginContainer.plugins)
            {
                paths.Add(plugin.paths.package);
            }
            var sourceArchiveFileName = Path.GetFileNameWithoutExtension(packagePath) + "_Source.zip";

            if (includeSourceZipInPackage)
            {
                var sourceArchivePath = Path.Combine(Paths.assets, sourceArchiveFileName);
                paths.Add(sourceArchivePath);
                CreateSourceZip(silent, sourceArchivePath);
            }

            var assetPathNames = paths.Select(PathUtility.FromProject).ToArray();

            Debug.Log(string.Join("\n", assetPathNames));
            AssetDatabase.ExportPackage(assetPathNames, packagePath, ExportPackageOptions.Recurse);

            if (!includeSourceZipInPackage)
            {
                CreateSourceZip(silent, Path.Combine(packageDirectory, sourceArchiveFileName));
            }

            if (!silent)
            {
                ProgressUtility.ClearProgressBar();
            }
        }
Ejemplo n.º 2
0
        private static void ExportReleasePackage()
        {
            if (!PrepareForRelease())
            {
                return;
            }

            var packagePath = EditorUtility.SaveFilePanel("Export Release Package",
                                                          Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                                                          "Peek_" + instance.version.ToString().Replace(".", "_").Replace(" ", "_"),
                                                          "unitypackage");

            if (packagePath == null)
            {
                return;
            }

            var packageDirectory = Path.GetDirectoryName(packagePath);

            ProgressUtility.DisplayProgressBar("Exporting Release Package", "Creating Unity Package...", 0);

            var paths = new List <string>();

            foreach (var product in ProductContainer.products)
            {
                paths.Add(product.rootPath);
            }

            foreach (var plugin in PluginContainer.plugins)
            {
                paths.Add(plugin.paths.package);
            }

            AssetDatabase.ExportPackage(paths.Select(PathUtility.FromProject).ToArray(), packagePath, ExportPackageOptions.Recurse);

            ProgressUtility.ClearProgressBar();

            if (EditorUtility.DisplayDialog("Export Release Package", "Release package export complete.\nOpen containing folder?", "Open Folder", "Close"))
            {
                Process.Start(packageDirectory);
            }
        }
Ejemplo n.º 3
0
        public static void Update()
        {
            if (!File.Exists(BoltFlow.Paths.unitOptions))
            {
                Build();
                return;
            }

            lock (@lock)
            {
                using (ProfilingUtility.SampleBlock("Update Unit Database"))
                {
                    using (NativeUtility.Module("sqlite3.dll"))
                    {
                        var progressTitle = "Updating unit database...";

                        SQLiteConnection database = null;

                        try
                        {
                            VersionControlUtility.Unlock(BoltFlow.Paths.unitOptions);

                            var steps = 7f;
                            var step  = 0f;

                            ProgressUtility.DisplayProgressBar(progressTitle, "Connecting to database...", step++ / steps);

                            database = new SQLiteConnection(BoltFlow.Paths.unitOptions);

                            ProgressUtility.DisplayProgressBar(progressTitle, "Updating type mappings...", step++ / steps);

                            UpdateTypeMappings();

                            ProgressUtility.DisplayProgressBar(progressTitle, "Fetching modified scripts...", step++ / steps);

                            var modifiedScriptGuids = GetModifiedScriptGuids().Distinct().ToHashSet();

                            ProgressUtility.DisplayProgressBar(progressTitle, "Fetching deleted scripts...", step++ / steps);

                            var deletedScriptGuids = GetDeletedScriptGuids().Distinct().ToHashSet();

                            ProgressUtility.DisplayProgressBar(progressTitle, "Updating codebase...", step++ / steps);

                            var modifiedScriptTypes = modifiedScriptGuids.SelectMany(GetScriptTypes).ToArray();

                            UpdateCodebase(modifiedScriptTypes);

                            var outdatedScriptGuids = new HashSet <string>();
                            outdatedScriptGuids.UnionWith(modifiedScriptGuids);
                            outdatedScriptGuids.UnionWith(deletedScriptGuids);

                            ProgressUtility.DisplayProgressBar(progressTitle, "Removing outdated unit options...", step++ / steps);

                            options?.RemoveWhere(option => outdatedScriptGuids.Overlaps(option.sourceScriptGuids));

                            // We want to use the database level WHERE here for speed,
                            // so we'll run multiple queries, one for each outdated script GUID.

                            foreach (var outdatedScriptGuid in outdatedScriptGuids)
                            {
                                foreach (var outdatedRowId in database.Table <UnitOptionRow>()
                                         .Where(row => row.sourceScriptGuids.Contains(outdatedScriptGuid))
                                         .Select(row => row.id))
                                {
                                    database.Delete <UnitOptionRow>(outdatedRowId);
                                }
                            }

                            ProgressUtility.DisplayProgressBar(progressTitle, "Converting codebase to unit options...", step++ / steps);

                            var newOptions = new HashSet <IUnitOption>(modifiedScriptGuids.SelectMany(GetScriptTypes)
                                                                       .Distinct()
                                                                       .SelectMany(GetIncrementalOptions));

                            var rows = new HashSet <UnitOptionRow>();

                            float progress = 0;

                            foreach (var newOption in newOptions)
                            {
                                options?.Add(newOption);

                                try
                                {
                                    ProgressUtility.DisplayProgressBar(progressTitle, newOption.label, (step / steps) + ((1 / step) * (progress / newOptions.Count)));
                                    rows.Add(newOption.Serialize());
                                }
                                catch (Exception ex)
                                {
                                    Debug.LogError($"Failed to serialize option '{newOption.GetType()}'.\n{ex}");
                                }

                                progress++;
                            }

                            ProgressUtility.DisplayProgressBar(progressTitle, "Writing to database...", 1);

                            try
                            {
                                database.InsertAll(rows);
                            }
                            catch (Exception ex)
                            {
                                Debug.LogError($"Failed to write options to database.\n{ex}");
                            }

                            // Make sure the database is touched to the current date,
                            // even if we didn't do any change. This will avoid unnecessary
                            // analysis in future update checks.
                            File.SetLastWriteTimeUtc(BoltFlow.Paths.unitOptions, DateTime.UtcNow);
                        }
                        finally
                        {
                            database?.Close();
                            ProgressUtility.ClearProgressBar();
                            UnityAPI.Async(AssetDatabase.Refresh);
                            //ConsoleProfiler.Dump();
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private static void Load()
        {
            if (File.Exists(BoltFlow.Paths.unitOptions))
            {
                // Update before loading if required, ensuring no "in-between" state
                // where the loaded options are not yet loaded.
                // The update code will not touch the options array if it is null.
                if (BoltFlow.Configuration.updateUnitsAutomatically)
                {
                    try
                    {
                        ProgressUtility.DisplayProgressBar("Checking for codebase changes...", null, 0);

                        if (requiresUpdate)
                        {
                            Update();
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.LogError($"Failed to update unit options.\nRetry with 'Tools > Bolt > Update Unit Options...'.\n{ex}");
                    }
                    finally
                    {
                        ProgressUtility.ClearProgressBar();
                    }
                }

                lock (@lock)
                {
                    using (ProfilingUtility.SampleBlock("Load Unit Database"))
                    {
                        using (NativeUtility.Module("sqlite3.dll"))
                        {
                            ProgressUtility.DisplayProgressBar("Loading unit database...", null, 0);

                            SQLiteConnection database = null;

                            try
                            {
                                database = new SQLiteConnection(BoltFlow.Paths.unitOptions, SQLiteOpenFlags.ReadOnly);

                                int total;

                                total = database.Table <UnitOptionRow>().Count();

                                var progress = 0f;

                                options = new HashSet <IUnitOption>();

                                var failedOptions = new Dictionary <UnitOptionRow, Exception>();

                                foreach (var row in database.Table <UnitOptionRow>())
                                {
                                    try
                                    {
                                        var option = row.ToOption();

                                        options.Add(option);
                                    }
                                    catch (Exception rowEx)
                                    {
                                        failedOptions.Add(row, rowEx);
                                    }

                                    ProgressUtility.DisplayProgressBar("Loading unit database...", LudiqCore.Configuration.humanNaming ? row.labelHuman : row.labelProgrammer, progress++ / total);
                                }

                                if (failedOptions.Count > 0)
                                {
                                    var sb = new StringBuilder();

                                    sb.AppendLine($"{failedOptions.Count} unit options failed to load and were skipped.");
                                    sb.AppendLine("Try rebuilding the unit options with 'Tools > Bolt > Build Unit Options' to purge outdated units.");
                                    sb.AppendLine();

                                    foreach (var failedOption in failedOptions)
                                    {
                                        sb.AppendLine(failedOption.Key.favoriteKey);
                                    }

                                    sb.AppendLine();

                                    foreach (var failedOption in failedOptions)
                                    {
                                        sb.AppendLine(failedOption.Key.favoriteKey + ": ");
                                        sb.AppendLine(failedOption.Value.ToString());
                                        sb.AppendLine();
                                    }

                                    Debug.LogWarning(sb.ToString());
                                }
                            }
                            catch (Exception ex)
                            {
                                options = new HashSet <IUnitOption>();
                                Debug.LogError($"Failed to load unit options.\nTry to rebuild them with 'Tools > Bolt > Build Unit Options'.\n\n{ex}");
                            }
                            finally
                            {
                                database?.Close();
                                //ConsoleProfiler.Dump();
                                ProgressUtility.ClearProgressBar();
                            }
                        }
                    }
                }
            }
            else if (!BoltFlow.Configuration.editorSetupCompleted)
            {
                Debug.LogWarning("Missing unit options.\nCreate them with 'Tools > Bolt > Unit Options Wizard...'.");
            }
        }
Ejemplo n.º 5
0
        public static void Build()
        {
            var progressTitle = "Building unit database...";

            lock (@lock)
            {
                using (ProfilingUtility.SampleBlock("Update Unit Database"))
                {
                    using (NativeUtility.Module("sqlite3.dll"))
                    {
                        SQLiteConnection database = null;

                        try
                        {
                            ProgressUtility.DisplayProgressBar(progressTitle, "Creating database...", 0);

                            if (File.Exists(BoltFlow.Paths.unitOptions))
                            {
                                VersionControlUtility.Unlock(BoltFlow.Paths.unitOptions);
                                File.Delete(BoltFlow.Paths.unitOptions);
                            }

                            PathUtility.CreateParentDirectoryIfNeeded(BoltFlow.Paths.unitOptions);
                            database = new SQLiteConnection(BoltFlow.Paths.unitOptions);
                            database.CreateTable <UnitOptionRow>();

                            ProgressUtility.DisplayProgressBar(progressTitle, "Updating codebase...", 0);

                            UpdateCodebase();

                            ProgressUtility.DisplayProgressBar(progressTitle, "Updating type mappings...", 0);

                            UpdateTypeMappings();

                            ProgressUtility.DisplayProgressBar(progressTitle, "Converting codebase to unit options...", 0);

                            options = new HashSet <IUnitOption>(GetStaticOptions());

                            var rows = new HashSet <UnitOptionRow>();

                            var progress          = 0;
                            var lastShownProgress = 0f;

                            foreach (var option in options)
                            {
                                try
                                {
                                    var shownProgress = (float)progress / options.Count;

                                    if (shownProgress > lastShownProgress + 0.01f)
                                    {
                                        ProgressUtility.DisplayProgressBar(progressTitle, "Converting codebase to unit options...", shownProgress);
                                        lastShownProgress = shownProgress;
                                    }

                                    rows.Add(option.Serialize());
                                }
                                catch (Exception ex)
                                {
                                    Debug.LogError($"Failed to save option '{option.GetType()}'.\n{ex}");
                                }

                                progress++;
                            }

                            ProgressUtility.DisplayProgressBar(progressTitle, "Writing to database...", 1);

                            try
                            {
                                database.CreateTable <UnitOptionRow>();
                                database.InsertAll(rows);
                            }
                            catch (Exception ex)
                            {
                                Debug.LogError($"Failed to write options to database.\n{ex}");
                            }
                        }
                        finally
                        {
                            database?.Close();
                            ProgressUtility.ClearProgressBar();
                            AssetDatabase.Refresh();
                            //ConsoleProfiler.Dump();
                        }
                    }
                }
            }
        }