aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Autooar/AutooarModule.cs
blob: 6c109289bcd5cef6a7bce6177afae6cb1a25d866 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Timers;
using Nini.Config;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;

namespace OpenSim.Region.OptionalModules.Autooar
{
    public class AutooarModule : IRegionModule
    {
        private readonly Timer m_timer = new Timer(60000*20);
        private readonly List<Scene> m_scenes = new List<Scene>();
        private IConfigSource config;
        private bool m_enabled = false;
        

        public void Initialise(Scene scene, IConfigSource source)
        {
            m_scenes.Add(scene);
            config = source;
        }

        public void PostInitialise()
        {
            if(config.Configs["autooar"] != null)
            {
                m_enabled = config.Configs["autooar"].GetBoolean("Enabled", m_enabled);
            }

            if(m_enabled)
            {
                m_timer.Elapsed += m_timer_Elapsed;
                m_timer.AutoReset = true;
                m_timer.Start();
            }
        }

        void m_timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (!Directory.Exists("autooars"))
                Directory.CreateDirectory("autooars");

            foreach (Scene scene in m_scenes)
            {
                IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>();

                archiver.ArchiveRegion(Path.Combine("autooars",
                                                    scene.RegionInfo.RegionName + "_" + scene.RegionInfo.RegionLocX +
                                                    "x" + scene.RegionInfo.RegionLocY + ".oar.tar.gz"));
            }
        }

        public void Close()
        {
            if (m_timer.Enabled)
                m_timer.Stop();
        }

        public string Name
        {
            get { return "Automatic OAR Module"; }
        }

        public bool IsSharedModule
        {
            get { return true; }
        }
    }
}