internal string fetchZwiftAuthToken()
        {
            if (user.Length < 1 || password.Length < 1)
            {
                return(null);
            }

            var qs = new Dictionary <string, string>
            {
                { "client_id", "Zwift_Mobile_Link" },
                { "grant_type", "password" },
                { "username", user },
                { "password", password }
            };

            var content = new FormUrlEncodedContent(qs);

            try
            {
                var response = client.PostAsync("https://secure.zwift.com/auth/realms/zwift/tokens/access/codes", content).Result;
                if (response.IsSuccessStatusCode)
                {
                    var     json   = response.Content.ReadAsStringAsync().Result;
                    dynamic result = serializer.Deserialize(json, typeof(object));
                    return(result.access_token);
                }
            }
            catch (Exception e)
            {
                lapi.Log(API.LogType.Error, "ZWIFT_RM_API.dll: fetchZwiftAuthToken error: " + e.Message);
            };
            return("");
        }
예제 #2
0
        public void UpdateStatus(Rainmeter.API rm = null)
        {
            if (rm != null)
            {
                this._SkinName = rm.GetSkinName();
                this._Handle   = rm.GetSkinWindow();
            }

            RECT rct;

            if (GetWindowRect(this._Handle, out rct))
            {
                this._X = rct.Left;
                this._Y = rct.Top;
                this._W = rct.Right - rct.Left;
                this._H = rct.Bottom - rct.Top;
            }
            else
            {
                rm.Log(API.LogType.Error,
                       "Rainmeter told us the HWND for window '" + this._SkinName + "' is " + this._Handle.ToInt32().ToString() + "L, but couldn't receive a proper RECT from it");
            }

            this._IsTopmost = ((GetWindowLong(this._Handle, GWL_EXSTYLE) & WS_EX_TOPMOST) > 0);
        }
        /*
         * Example activity element in array, notice each entry has profile info as well as "sport" on case RUN and cycling should be sepearte
         *
         * {
         *  id_str: '1234567890',
         *  id: 1234567890,
         *  profileId: 1234567890,
         *  profile: {
         *    id: 1234567890,
         *    publicId: '1234567890-1234567890-1234567890',
         *    firstName: 'Example',
         *    lastName: 'Name',
         *    male: true,
         *    imageSrc: 'https://static-cdn.zwift.com/prod/profile/12345678901234567890',
         *    imageSrcLarge: 'https://static-cdn.zwift.com/prod/profile/12345678901234567890',
         *    playerType: 'NORMAL',
         *    countryAlpha3: 'deu',
         *    countryCode: 276,
         *    useMetric: true,
         *    riding: false,
         *    privacy: [Object],
         *    socialFacts: null,
         *    worldId: null,
         *    enrolledZwiftAcademy: false,
         *    playerTypeId: 1,
         *    playerSubTypeId: null,
         *    currentActivityId: null
         *  },
         *  worldId: 1,
         *  name: 'Zwift Run - Watopia',
         *  description: null,
         *  privateActivity: true,
         *  sport: 'RUNNING',
         *  startDate: '2021-01-01T00:00:00.000+0000',
         *  endDate: '2021-01-01T01:00:00.00+0000',
         *  lastSaveDate: '2021-01-01T01:00:00.00+0000',
         *  autoClosed: false,
         *  duration: '1:00',
         *  distanceInMeters: 1234.56,
         *  fitFileBucket: 's3-fit-prd-uswest2-zwift',
         *  fitFileKey: 'prod/123456/123456-123456123456',
         *  totalElevation: 0,
         *  avgWatts: 0,
         *  rideOnGiven: false,
         *  activityRideOnCount: 42,
         *  activityCommentCount: 0,
         *  snapshotList: null,
         *  calories: 4242.00,
         *  primaryImageUrl: 'https://s3-fit-prd-uswest2-zwift.s3.amazonaws.com/prod/img/123456-123456123456123456',
         *  movingTimeInMs: 123456,
         *  privacy: 'PRIVATE',
         *  topNotableMoment: {
         *    notableMomentTypeId: 1,
         *    activityId: 123456123456123456123456,
         *    incidentTime: 123456,
         *    priority: 8,
         *    aux1: '3',
         *    aux2: '300'
         *  },
         *  avgSpeedInMetersPerSecond: 2.42,
         *  feedImageThumbnailUrl: 'https://s3-fit-prd-uswest2-zwift.s3.amazonaws.com/prod/img/1234561-23456123456123456',
         *  eventSubgroupId: null,
         *  eventId: null,
         *  clubActivity: false
         * },
         *
         */

        internal override void Reload(Rainmeter.API api, ref double maxValue)
        {
            base.Reload(api, ref maxValue);
            Name = api.GetMeasureName();
            Skin = api.GetSkin();

            user      = api.ReadString("zwiftUser", "");
            password  = api.ReadString("zwiftPass", "");
            pastMonth = api.ReadInt("pastMonth", 0);

            var feedArr = fetchZwiftFeed();

            try
            {
                foreach (var activity in feedArr)
                {
                    CultureInfo provider = CultureInfo.InvariantCulture;
                    DateTime    start    = DateTime.Parse(activity.startDate);
                    var         month    = new DateTime(start.Year, start.Month, 1);
                    if (!distanceDict.ContainsKey(month))
                    {
                        distanceDict[month] = 0;
                    }
                    distanceDict[month] += Convert.ToDouble(activity.distanceInMeters);
                }
            }
            catch (Exception e)
            {
                api.Log(API.LogType.Error, "ZWIFT_RM_API.dll: Reload error:" + e.Message);
            };
        }
        internal virtual void Reload(Rainmeter.API api, ref double maxValue)
        {
            string type = api.ReadString("Type", "");

            switch (type.ToLowerInvariant())
            {
            case "name":
                this.Type = MeasureType.SongName;
                break;

            case "artists":
                this.Type = MeasureType.Artists;
                break;

            case "album":
                this.Type = MeasureType.Album;
                break;

            case "lyric":
                this.Type = MeasureType.Lyric;
                break;

            case "islyrictranslated":
                this.Type = MeasureType.IsLyricTranslated;
                break;

            case "translatedlyric":
                this.Type = MeasureType.TranslatedLyric;
                break;

            default:
                api.Log(API.LogType.Error, "ParentChild.dll: Type=" + type + " not valid");
                break;
            }
        }
        internal virtual void Reload(Rainmeter.API api, ref double maxValue)
        {
            string type = api.ReadString("Type", "current");

            switch (type.ToLowerInvariant())
            {
            case "current":
                Type = MeasureType.current;
                break;

            case "lastx":
                Type = MeasureType.lastX;
                break;

            case "min":
                Type = MeasureType.min;
                break;

            case "max":
                Type = MeasureType.max;
                break;

            default:
                api.Log(API.LogType.Error, "ZWIFT_RM_API.dll: Type=" + type + " not valid");
                break;
            }
        }
        internal void Reload(Rainmeter.API api, ref double maxValue)
        {
            string type = api.ReadString("Type", "");

            switch (type.ToLowerInvariant())
            {
            case "major":
                Type = MeasureType.Major;
                break;

            case "minor":
                Type = MeasureType.Minor;
                break;

            case "number":
                Type = MeasureType.Number;
                break;

            case "string":
                Type = MeasureType.String;
                break;

            default:
                api.Log(API.LogType.Error, "SystemVersion.dll: Type=" + type + " not valid");
                break;
            }
        }
예제 #7
0
        public static void Initialize(ref IntPtr data, IntPtr rm)
        {
            data = GCHandle.ToIntPtr(GCHandle.Alloc(new Measure()));
            Rainmeter.API api = (Rainmeter.API)rm;

            Measure measure = (Measure)data;

            measure.synth  = new SpeechSynthesizer();
            measure.prompt = new Prompt("");

            measure.voices     = measure.synth.GetInstalledVoices();
            measure.voiceCount = measure.voices.Count;

            measure.synth.SetOutputToDefaultAudioDevice();

            int debug = api.ReadInt("Debug", 0);

            if (debug == 1)
            {
                api.Log(API.LogType.Notice, "------------------------------");
                api.Log(API.LogType.Notice, "* Speech.dll - GetInstalledVoices() API");

                int index = 1;
                foreach (InstalledVoice voice in measure.voices)
                {
                    VoiceInfo info = voice.VoiceInfo;

                    api.LogF(API.LogType.Notice, "Index: {0}", index);
                    api.LogF(API.LogType.Notice, "  Name          : {0}", info.Name);
                    api.LogF(API.LogType.Notice, "  Gender        : {0}", info.Gender);
                    api.LogF(API.LogType.Notice, "  Culture       : {0}", info.Culture);
                    api.LogF(API.LogType.Notice, "  Age           : {0}", info.Age);
                    api.LogF(API.LogType.Notice, "  Description   : {0}", info.Description);
                    api.LogF(API.LogType.Notice, "  ID            : {0}", info.Id);
                    api.LogF(API.LogType.Notice, "  Enabled       : {0}", voice.Enabled);

                    ++index;
                }

                api.Log(API.LogType.Notice, "------------------------------");
            }
        }
        /// <summary>
        /// Convert Unix time value to a DateTime object.
        /// </summary>
        /// <param name="unixTime">The Unix time stamp you want to convert to DateTime as a long.</param>
        /// <returns>Returns a DateTime object that represents value of the Unix time.</returns>
        public DateTime UnixTimeToDateTime(long unixTime)
        {
            try {
                System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
                dtDateTime = dtDateTime.AddSeconds(unixTime).ToLocalTime();

                return(dtDateTime);
            } catch {
                if (api_ref != null)
                {
                    api_ref.Log(API.LogType.Error, "UnixTimeConverter.dll: Could not convert input to DataTime object.");
                }

                // If an error happened, return the minimum value
                return(DateTime.MinValue);
            }
        }
예제 #9
0
파일: Main.cs 프로젝트: atrepalin/Rainmeter
        internal void ExecuteBang(string args)
        {
            bool go = false;

            lock (this.locker)
            {
                if (!this.IsExecuteBangRunning)
                {
                    this.IsExecuteBangRunning = true;
                    go = true;
                }
            }

            if (go)
            {
                ExecuteBangParam param = new ExecuteBangParam(args);
                if (ReadOptions(param))  // Read all options in main thread for thread-safety
                {
                    ThreadPool.QueueUserWorkItem(_ =>
                    {
                        try
                        {
                            ExecuteCommands(param);
                        }
                        catch (Exception ex)
                        {
                            rm.Log(API.LogType.Error, "C# plugin in ExecuteBang(), " + ex.GetType().ToString() + ": " + ex.Message);
                        }

                        lock (this.locker)
                        {
                            this.IsExecuteBangRunning = false;
                        }
                    });
                }
                else
                {
                    // No need to continue
                    lock (this.locker)
                    {
                        this.IsExecuteBangRunning = false;
                    }
                }
            }
        }
        internal override void Reload(Rainmeter.API api, ref double maxValue)
        {
            base.Reload(api, ref maxValue);

            string parentName = api.ReadString("ParentName", "");
            IntPtr skin       = api.GetSkin();

            // Find parent using name AND the skin handle to be sure that it's the right one.
            ParentMeasure = null;
            foreach (ParentMeasure parentMeasure in ParentMeasure.ParentMeasures)
            {
                if (parentMeasure.Skin.Equals(skin) && parentMeasure.Name.Equals(parentName))
                {
                    ParentMeasure = parentMeasure;
                }
            }

            if (ParentMeasure == null)
            {
                api.Log(API.LogType.Error, "ParentChild.dll: ParentName=" + parentName + " not valid");
            }
        }
        internal virtual void Reload(Rainmeter.API api, ref double maxValue)
        {
            string type = api.ReadString("Type", "");

            switch (type.ToLowerInvariant())
            {
            case "a":
                Type = MeasureType.A;
                break;

            case "b":
                Type = MeasureType.B;
                break;

            case "c":
                Type = MeasureType.C;
                break;

            default:
                api.Log(API.LogType.Error, "ParentChild.dll: Type=" + type + " not valid");
                break;
            }
        }
        public static void Reload(IntPtr data, IntPtr rm, ref double maxValue)
        {
            Measure measure = (Measure)data;

            Rainmeter.API api = (Rainmeter.API)rm;

            //Get starting value if one is defined
            int startValue = api.ReadInt("StartingValue", -1);

            //If string from option was null read from file
            if (startValue == -1)
            {
                char[] outString = new char[MAXSIZE];

                //Read from Rainmeter.data file, if no instace exists start at 0
                GetPrivateProfileString(PluginName, KeyName, "0", outString, MAXSIZE, API.GetSettingsFile());

                try
                {
                    //Need try catch just in case someone tampers with the file and the value stored is not a number
                    string intString = new string(outString);
                    measure.myCounter = Convert.ToInt32(intString);
                }
                catch
                {
                    api.Log(API.LogType.Error, "Error converting value stored in Rainmeter.data to integer");
                }
            }
            else
            {
                measure.myCounter = startValue;
            }

            //If store data is 1 then save data when measure is unloaded
            measure.storeData = api.ReadInt("StoreData", 0) == 1 ? true : false;
        }
예제 #13
0
파일: Util.cs 프로젝트: SnGmng/RainForms
        internal void LogDebug(string message)
        {
#if DEBUG
            api.Log(API.LogType.Debug, message);
#endif
        }
예제 #14
0
        public static void Reload(IntPtr data, IntPtr rm, ref double maxValue)
        {
            Measure measure = (Measure)data;

            Rainmeter.API api = (Rainmeter.API)rm;

            string name       = api.ReadString("Name", "");
            bool   nameExists = name != "" ? true : false;

            VoiceGender gender    = VoiceGender.NotSet;
            string      genderStr = api.ReadString("Gender", "").ToUpper();

            if (genderStr == "MALE")
            {
                gender = VoiceGender.Male;
            }
            else if (genderStr == "FEMALE")
            {
                gender = VoiceGender.Female;
            }
            else if (genderStr != "")
            {
                api.Log(API.LogType.Warning, "Speech.dll: Invalid gender");
            }
            bool genderExists = gender != VoiceGender.NotSet;

            measure.gender = gender;

            int index = api.ReadInt("Index", 0);

            measure.index = index;

            int volume = api.ReadInt("Volume", 100);

            if (volume < 0 || volume > 100)
            {
                volume = 100;
            }

            int rate = api.ReadInt("Rate", 0);

            if (rate < -10 || rate > 10)
            {
                rate = 0;
            }

            measure.synth.Volume = volume;
            measure.synth.Rate   = rate;

            // Setup voice
            int    i            = 1;
            String selectedName = "";

            foreach (InstalledVoice voice in measure.voices)
            {
                // If no options are "defined", use the first voice.
                if (!nameExists && !genderExists && (index <= 0))
                {
                    selectedName = voice.VoiceInfo.Name;
                    break;
                }

                // If name is defined, use this voice.
                if (nameExists && (name.ToUpper() == voice.VoiceInfo.Name.ToUpper()))
                {
                    selectedName = voice.VoiceInfo.Name;
                    break;
                }

                // If gender is defined, only look for voices of the same gender
                if (!nameExists && genderExists)
                {
                    if (gender != voice.VoiceInfo.Gender)
                    {
                        continue;
                    }

                    if (index > 0)
                    {
                        if (index == i)
                        {
                            selectedName = voice.VoiceInfo.Name;
                            break;
                        }

                        ++i;
                        continue;
                    }
                    else
                    {
                        selectedName = voice.VoiceInfo.Name;
                        break;
                    }
                }

                // Select by index
                if (!nameExists && index == i)
                {
                    selectedName = voice.VoiceInfo.Name;
                    break;
                }

                ++i;
            }

            measure.selectedName = selectedName;

            // Something went wrong
            //  Name is incorrect
            //  No matching gender was found
            //  Invalid index
            if (selectedName == "")
            {
                api.Log(API.LogType.Warning, "Speech.dll: Invalid Name, Gender and/or Index. Using best matching valid voice.");
            }
        }
        internal void Reload(Rainmeter.API api, ref double maxValue)
        {
            // Store API reference
            api_ref = api;

            string type = api.ReadString("Type", "");

            source = api.ReadString("Source", "");
            api.Log(API.LogType.Debug, $"Source: {source}");

            // Check data validity
            if (source != "")
            {
                if (source.Trim().Length < 9 && source.Trim().Length > 11)
                {
                    api.Log(API.LogType.Warning, "Source: data length is not between 9 and 11 characters.  Bad data?  Parsing anyway...");
                }

                convertedTime = UnixTimeToDateTime(source);
                api.Log(API.LogType.Debug, $"Converted Time: {convertedTime}");
            }

            switch (type.ToLowerInvariant())
            {
            case "second":
                Type = MeasureType.Second;
                break;

            case "minute":
                Type = MeasureType.Minute;
                break;

            case "hour":
                Type = MeasureType.Hour;
                break;

            case "day":
                Type = MeasureType.Day;
                break;

            case "month":
                Type = MeasureType.Month;
                break;

            case "year":
                Type = MeasureType.Year;
                break;

            case "dayofweek":
                Type = MeasureType.DayOfWeek;
                break;

            case "formatteddate":
                Type = MeasureType.FormattedDate;
                break;

            default:
                api.Log(API.LogType.Error, "UnixTimeConverter.dll: Type=" + type + " not valid");
                break;
            }
        }