예제 #1
0
        internal override void Compile(ElobuddyAddon addon)
        {
            var logFileName   = string.Format("compile_log_{0}.txt", addon.GetUniqueName());
            var logFile       = Path.Combine(Settings.Instance.Directories.TempDirectory, logFileName);
            var compileResult = ProjectCompiler.Compile(addon.ProjectFilePath, logFile);

            File.Delete(logFile);

            if (!compileResult.BuildSuccessful)
            {
                addon.SetState(AddonState.CompilingError);

                var logFileSavePath = Path.Combine(Settings.Instance.Directories.LogsDirectory, logFileName);
                File.WriteAllBytes(logFileSavePath, compileResult.LogFile);
                Log.Instance.DoLog(string.Format("Failed to compile project: \"{0}\". Build log file saved to \"{1}\".", addon.ProjectFilePath, logFileSavePath), Log.LogType.Error);
            }
            else
            {
                addon.SetState(AddonState.Ready);
                addon.Type = compileResult.Type;

                if (!addon.IsLocal)
                {
                    var split = addon.Url.Split('/');
                    addon.Author = split.Length > 3 ? split[3] : "";
                }

                var exePath = addon.GetOutputFilePath();
                var pdpPath = Path.Combine(Path.GetDirectoryName(exePath), compileResult.PdbFileName ?? "");

                FileHelper.SafeWriteAllBytes(exePath, compileResult.OutputFile);

                if (Settings.Instance.DeveloperMode && compileResult.PdbFile != null)
                {
                    FileHelper.SafeWriteAllBytes(pdpPath, compileResult.PdbFile);
                }
                else if (File.Exists(pdpPath))
                {
                    try
                    {
                        File.Delete(pdpPath);
                    }
                    catch
                    {
                        // ignored
                    }
                }

                addon.Version = FileVersionInfo.GetVersionInfo(exePath).FileVersion;

                Log.Instance.DoLog(string.Format("Successfully compiled project: \"{0}\".", addon.ProjectFilePath));
            }
        }
        public InstalledAddonDataGridItem(ElobuddyAddon addon)
        {
            if (!addon.IsAvailable)
            {
                addon.SetState(AddonState.BuddyOnly);
            }

            Addon = addon;
            Refresh();
        }
예제 #3
0
        internal override void Compile(ElobuddyAddon addon)
        {
            SignedAddonHeader header;

            byte[] assembly;

            if (Verify(File.ReadAllBytes(addon.ProjectFilePath), out header, out assembly))
            {
                // buddy check
                addon.IsBuddyAddon = header.Data.CData[0] != 0;

                addon.Type    = header.Data.IsLibrary ? AddonType.Library : AddonType.Executable;
                addon.Author  = header.Data.Author;
                addon.Version = header.Data.Version;

                FileHelper.SafeWriteAllBytes(addon.GetOutputFilePath(), assembly);
                addon.SetState(AddonState.Ready);
            }
            else
            {
                Log.Instance.DoLog(string.Format("Failed to install signed addon: \"{0}\". The addon is not properly signed!", addon.ProjectFilePath), Log.LogType.Error);
                addon.SetState(AddonState.CompilingError);
            }
        }
예제 #4
0
        public static void UpdateAddons(ElobuddyAddon[] addons, bool compileOnly = false)
        {
            if (IsRunning)
            {
                return;
            }

            Log.Instance.DoLog("Updating Elobuddy addons.");
            Events.RaiseOnAddonUpdatePrepare(EventArgs.Empty);

            // Group addons based on repository directory
            var groups = from addon in addons
                         group addon by addon.GetRemoteAddonRepositoryDirectory()
                         into newGroup
                         orderby newGroup.Key
                         select newGroup;

            var threadDictionary = new Dictionary <AddonUpdateThread, ElobuddyAddon[]>();

            foreach (var group in groups)
            {
                var thread = new AddonUpdateThread();
                threadDictionary.Add(thread, group.ToArray());
            }

            // Update UI before starting
            foreach (var t in threadDictionary.Values)
            {
                var addon = t.FirstOrDefault();
                if (addon != null)
                {
                    addon.SetState(addon.IsLocal
                        ? AddonState.WaitingForCompile
                        : compileOnly ? AddonState.WaitingForCompile : AddonState.WaitingForUpdate);
                }

                for (var i = 1; i < t.Length; i++)
                {
                    t[i].SetState(AddonState.WaitingForCompile);
                }
            }

            var compileQueue = new Queue <ElobuddyAddon>();

            _threadsWorking = threadDictionary.Count + 1;

            foreach (var t in threadDictionary)
            {
                t.Key.Start(args =>
                {
                    var _addons = args as ElobuddyAddon[];
                    var _addon  = _addons.FirstOrDefault();

                    if (_addon != null)
                    {
                        if (!_addon.IsLocal && !compileOnly)
                        {
                            _addon.SetState(AddonState.Updating);
                            _addon.Update(false, false);
                        }

                        _addon.SetState(AddonState.WaitingForCompile);
                    }

                    lock (SyncLock)
                    {
                        foreach (var a in _addons)
                        {
                            compileQueue.Enqueue(a);
                        }
                    }

                    Interlocked.Decrement(ref _threadsWorking);
                }, t.Value);
            }

            new AddonUpdateThread().Start(args =>
            {
                while (true)
                {
                    ElobuddyAddon _addon = null;

                    lock (SyncLock)
                    {
                        if (compileQueue.Count > 0)
                        {
                            _addon = compileQueue.Dequeue();
                        }
                    }

                    if (_addon != null)
                    {
                        _addon.SetState(AddonState.Compiling);
                        _addon.Compile();
                        _addon.RefreshDisplay();
                    }

                    lock (SyncLock)
                    {
                        if (Interlocked.Read(ref _threadsWorking) == 1 && compileQueue.Count == 0)
                        {
                            break;
                        }
                    }

                    Thread.Sleep(10);
                }

                Events.RaiseOnAddonUpdateFinished(EventArgs.Empty);
                Log.Instance.DoLog("Finished updating Elobuddy addons.");

                Interlocked.Decrement(ref _threadsWorking);
            }, null);
        }