<commit_before>﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace NAppUpdate.Framework.Tasks
{
    [UpdateTaskAlias("fileUpdate")]
    public class FileUpdateTask : IUpdateTask
    {
        public FileUpdateTask()
        {
            Attributes = new Dictionary<string, string>();
            UpdateConditions = new NAppUpdate.Framework.Conditions.BooleanCondition();
        }

        internal string tempFile = null;
        private string destinationFile;

        #region IUpdateTask Members

        public IDictionary<string, string> Attributes { get; private set; }

        public string Description { get; set; }

        public NAppUpdate.Framework.Conditions.BooleanCondition UpdateConditions { get; set; }

        public bool Prepare(NAppUpdate.Framework.Sources.IUpdateSource source)
        {
            tempFile = null;
            if (!Attributes.ContainsKey("updateTo"))
                return true; // Errorneous case, but there's nothing to prepare...

            try
            {
                string tempFileLocal = Path.Combine(UpdateManager.Instance.TempFolder, Guid.NewGuid().ToString());
                if (!source.GetData(Attributes["updateTo"], UpdateManager.Instance.BaseUrl, ref tempFileLocal))
                    return false;

                tempFile = tempFileLocal;
            }
            catch { return false; }

            if (Attributes.ContainsKey("sha256-checksum"))
            {
                string checksum = Utils.FileChecksum.GetSHA256Checksum(tempFile);
                if (!checksum.Equals(Attributes["sha256-checksum"]))<commit_msg>Don't require an [updateTo] in FileUpdateTask, base on localPath when its absent instead<commit_after>﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace NAppUpdate.Framework.Tasks
{
    [UpdateTaskAlias("fileUpdate")]
    public class FileUpdateTask : IUpdateTask
    {
        public FileUpdateTask()
        {
            Attributes = new Dictionary<string, string>();
            UpdateConditions = new NAppUpdate.Framework.Conditions.BooleanCondition();
        }

        internal string tempFile = null;
        private string destinationFile;

        #region IUpdateTask Members

        public IDictionary<string, string> Attributes { get; private set; }

        public string Description { get; set; }

        public NAppUpdate.Framework.Conditions.BooleanCondition UpdateConditions { get; set; }

        public bool Prepare(NAppUpdate.Framework.Sources.IUpdateSource source)
        {
            if (!Attributes.ContainsKey("localPath"))
                return true; // Errorneous case, but there's nothing to prepare to...

            string fileName;
            if (Attributes.ContainsKey("updateTo"))
                fileName = Attributes["updateTo"];
            else
                fileName = Attributes["localPath"];

            tempFile = null;

            try
            {
                string tempFileLocal = Path.Combine(UpdateManager.Instance.TempFolder, Guid.NewGuid().ToString());
                if (!source.GetData(fileName, UpdateManager.Instance.BaseUrl, ref tempFileLocal))
                    return false;

                tempFile = tempFileLocal;
            }
            catch { return false; }

            if (Attributes.ContainsKey("sha256-checksum"))
            {
                string checksum = Utils.FileChecksum.GetSHA256Checksum(tempFile);
                if (!checksum.Equals(Attributes["sha256-checksum"]))
{'fraction_non_alphanumeric': 0.08947664603263927, 'fraction_numerical': 0.005064715813168261, 'mean_word_length': 2.261467889908257, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2487786', 'n_tokens_mistral': 896, 'n_tokens_neox': 848, 'n_words': 205}