ExtensionHelper.cs #1

  • //
  • guest/
  • christoph_leithner/
  • piper/
  • main/
  • windows/
  • R1.1/
  • Perforce/
  • Helper/
  • ExtensionHelper.cs
  • View
  • Commits
  • Open Download .zip Download (2 KB)
//
// Copyright 2014 Perforce Software Inc.
//

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Perforce.Helper {
    public class ExtensionHelper {

        private string _mappingFileName = Application.LocalUserAppDataPath + @"\mappings.json";
        private Dictionary<string, string> _mappings;

        public ExtensionHelper() {
            LoadMappings();
        }

        public Dictionary<string, string> Mappings {
            get { return _mappings; }
            set { _mappings = value; }
        }

        public string GetMapping(string extension) {
            string value = null;
            _mappings.TryGetValue(extension, out value);
            return value;
        }

        public void SetMapping(string extension, string value) {
            if (_mappings == null) {
                _mappings = new Dictionary<string, string>(StringComparer.CurrentCultureIgnoreCase);
            }
            _mappings.Add(extension, value);
        }

        public void SaveMappings() {
            // convert mappings to json
            string json = JsonConvert.SerializeObject(_mappings, Formatting.Indented);
            // write to file
            File.WriteAllText(_mappingFileName, json);
        }

        public void LoadMappings() {
            if (_mappingFileName != null && File.Exists(_mappingFileName)) {
                // read json from file
                var json = File.ReadAllText(_mappingFileName);
                // convert to dictionary
                _mappings = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
            } else {
                _mappings = new Dictionary<string, string>(StringComparer.CurrentCultureIgnoreCase);
                SaveMappings();
            }
        }
    }
}
# Change User Description Committed
#1 16817 christoph_leithner "Forking branch Main of perforce-software-piper to christoph_leithner-piper."
//guest/perforce_software/piper/main/windows/R1.1/Perforce/Helper/ExtensionHelper.cs
#1 16507 perforce_software Move to main branch.
//guest/perforce_software/piper/windows/R1.1/Perforce/Helper/ExtensionHelper.cs
#2 13572 alan_petersen updating R1.1
#1 11256 alan_petersen Populate //guest/perforce_software/piper/windows/R1.1/...
from //guest/perforce_software/piper/windows/main/....
//guest/perforce_software/piper/windows/main/Perforce/Helper/ExtensionHelper.cs
#1 11255 alan_petersen Rename/move file(s)
//guest/perforce_software/piper/windows/Perforce/Helper/ExtensionHelper.cs
#2 10800 alan_petersen UPDATE:
- Various fixes   
    - fixed bug in which double-click would not work on files locked by the user
    - fixed bug in helper application dialog
    - added 'reconcile files' to context menu in Workspace view
    - updated submit dialog to display error message if submit fails
#1 10761 alan_petersen initial drop of Piper for Windows....

this version still has _many_ bugs (er... i mean "unintended features") but I will be updating it over the next week as more stability is added.