<commit_before>﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Input;
using Torrent.Client;
namespace Torrent.Gui
{
    class MainViewModel:ViewModelBase
    {
        public ObservableCollection<Transfer> Transfers { get; private set; }

        public ICommand AddTransferCommand { get; set; }
        public ICommand RemoveTransferCommand { get; set; }

        public IOService IOService { get; private set; }

        public MainViewModel(IOService ioService)
        {
            Transfers = new ObservableCollection<Transfer>();
            AddTransferCommand = new RelayCommand<string>(param => AddTransfer(param));
            RemoveTransferCommand = new RelayCommand<Transfer>(param => RemoveTransfer(param));
            IOService = ioService;
        }

        private void RemoveTransfer(Transfer transfer)
        {
            Transfers.Remove(transfer);
        }

        private void AddTransfer(string path)
        {
            if (path != null && Path.GetExtension(path) != ".torrent")
            {
                IOService.ShowErrorMessage("Not a valid torrent file", "Only files with a .torrent extension are recognized as valid.");
                return;
            }

            try
            {
                string filePath = path == null ? IOService.OpenFile("Torrent files|*.torrent") : path;
                string saveFolder = null;
                if(filePath != null) 
                    saveFolder = IOService.OpenFolder(Path.GetFileName(path));

                if (filePath != null && saveFolder != null)
                {
                    var transfer = new Transfer(new TorrentTransfer(filePath, saveFolder));
                    if (!Transfers.Any(t => t.InfoHash == transfer.InfoHash))
                        Transfers.Add(transfer);
                    else
                        IOService.ShowErrorMessage("Torrent transfer already exists",<commit_msg>Fixed bug when opening torrent file<commit_after>﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Input;
using Torrent.Client;
namespace Torrent.Gui
{
    class MainViewModel:ViewModelBase
    {
        public ObservableCollection<Transfer> Transfers { get; private set; }

        public ICommand AddTransferCommand { get; set; }
        public ICommand RemoveTransferCommand { get; set; }

        public IOService IOService { get; private set; }

        public MainViewModel(IOService ioService)
        {
            Transfers = new ObservableCollection<Transfer>();
            AddTransferCommand = new RelayCommand<string>(param => AddTransfer(param));
            RemoveTransferCommand = new RelayCommand<Transfer>(param => RemoveTransfer(param));
            IOService = ioService;
        }

        private void RemoveTransfer(Transfer transfer)
        {
            Transfers.Remove(transfer);
        }

        private void AddTransfer(string path)
        {
            if (path != null && Path.GetExtension(path) != ".torrent")
            {
                IOService.ShowErrorMessage("Not a valid torrent file", "Only files with a .torrent extension are recognized as valid.");
                return;
            }

            try
            {
                string filePath = path == null ? IOService.OpenFile("Torrent files|*.torrent") : path;
                string saveFolder = null;
                if(!string.IsNullOrEmpty(filePath)) 
                    saveFolder = IOService.OpenFolder(Path.GetFileName(path));

                if (filePath != null && saveFolder != null)
                {
                    var transfer = new Transfer(new TorrentTransfer(filePath, saveFolder));
                    if (!Transfers.Any(t => t.InfoHash == transfer.InfoHash))
                        Transfers.Add(transfer);
                    else
                        IOService.ShowErrorMessage("Torrent transfer already exists",
{'fraction_non_alphanumeric': 0.08866995073891626, 'fraction_numerical': 0.0, 'mean_word_length': 2.1608598962194216, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '3488390', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1020, 'n_words': 263}