Иконка ресурса

FREE PluginAutoUpdate : 1.0.0 1.0.0

Нет прав для скачивания
C#:
using Oxide.Core.Libraries.Covalence;
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using Oxide.Core.Plugins;

namespace Oxide.Plugins
{
    [Info("PluginAutoUpdate", "Toxide", "1.0.0")]
    public class PluginAutoUpdate : CovalencePlugin
    {
        [PluginReference]
        private Plugin DisableSandbox;

        private const float UPDATE_INTERVAL = 5f;
        private const string SOURCE_DIR = @"C:\Users\ExampleUser\RustDevelopment\RustPlugins\";
        private const string TARGET_DIR = @"C:\Users\ExampleUser\Rust\steamcmd\steamapps\common\rust_dedicated\oxide\plugins";

        private Dictionary<string, int> hashList;
        private Timer fileTimer;


        void OnServerInitialized()
        {
            if (DisableSandbox == null)
            {
                PrintError("PluginAutoUpdate requires DisableSandbox to work!");
                server.Command($"o.unload {Name}");
                return;
            }

            hashList = new Dictionary<string, int>();
            fileTimer = timer.Every(UPDATE_INTERVAL, UpdateFile);
        }

        void Unload()
        {
            fileTimer.Destroy();
        }

        private void UpdateFile()
        {
            try
            {
                string[] files = Directory.GetFiles(SOURCE_DIR);
                foreach (string file in files)
                {
                    if (Path.GetFileName(file) == Path.GetFileName(Filename)) continue;
                    if (Path.GetExtension(file) != ".cs") continue;

                    string destFile = TARGET_DIR + @"\" + Path.GetFileName(file);
                    if (!File.Exists(destFile)) continue;

                    int lastHash = 0;
                    int currentHash = File.ReadAllText(file).GetHashCode();

                    if (hashList.ContainsKey(file))
                        lastHash = hashList[file];
                    else
                        hashList.Add(file, currentHash);

                    if (currentHash != lastHash)
                    {
                        File.Copy(file, destFile, true);
                        hashList[file] = currentHash;

                        Puts($"Updated {Path.GetFileName(file)}");
                    }
                }
            } 
            catch(Exception ex)
            {
                PrintError(ex.ToString());
            }
        }

    }
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху