Example #1
0
    void ClientMessage(string[] args)
    {
        if (args == null || args.Length != 2 || args[0] != "delete-current-file")
        {
            return;
        }

        if (args[1] == "delete")
        {
            FileToDelete = Core.GetPropertyString("path");
            DeleteTime   = DateTime.Now;
            Core.CommandV("show-text", "Press 1 to delete file", "10000");
        }
        else if (args[1] == "confirm")
        {
            TimeSpan ts   = DateTime.Now - DeleteTime;
            string   path = Core.GetPropertyString("path");

            if (FileToDelete == path && ts.TotalSeconds < 10 && File.Exists(FileToDelete))
            {
                Core.CommandV("show-text", "");

                int count  = Core.GetPropertyInt("playlist-count");
                int pos    = Core.GetPropertyInt("playlist-pos");
                int newPos = pos == count - 1 ? pos - 1 : pos + 1;

                if (newPos > -1)
                {
                    Core.SetPropertyNumber("playlist-pos", newPos);
                }

                Core.Command("playlist-remove " + pos);

                App.RunTask(() => {
                    Thread.Sleep(2000);
                    FileSystem.DeleteFile(FileToDelete, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
                });
            }
        }
    }