Пример #1
0
        private static TrackerConfig InitializeConfig()
        {
            var t = new TrackerConfig()
            {
                LastPushDate  = DateTime.MinValue.Date,
                LastPushLine  = 0,
                PushToColumn  = "A",
                SheetName     = "",
                SpreadSheetId = ""
            };

            File.WriteAllText("config.json", JsonConvert.SerializeObject(t, Formatting.Indented));
            return(t);
        }
Пример #2
0
        static void Main(string[] args)
        {
            var waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, "GFL-OCR-RSC-Tracker", out bool createdNew);
            var signaled   = false;

            if (!createdNew)
            {
                waitHandle.Set();
                return;
            }

            LogFile = "logs\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
            Directory.CreateDirectory("logs");
            File.Create(LogFile).Dispose();

            cfg = TrackerConfig.GetConfig();
            BoundsCapturer b = new BoundsCapturer();

            Application.EnableVisualStyles();
            int[] values   = null;
            bool  accepted = false;

            while (!accepted)
            {
                values = null;
                while (values == null)
                {
                    b.CreateFinder();
                    ToFile(b.GeneratedBounds.ToString());
                    ToFile("Starting parsing");
                    values = b.GetValuesFromBound();
                    if (values == null)
                    {
                        ToFile("Couldn't find values, reopening capture window");
                        if (MessageBox.Show("Could not find resource values, retry capture?", "Error finding values", MessageBoxButtons.YesNo) == DialogResult.No)
                        {
                            Environment.Exit(0);
                        }
                    }
                }

                DialogResult r = MessageBox.Show("Manpower\tAmmo\t\tRations\t\tParts\n" + values[0] + "\t\t" + values[1] + "\t\t" + values[2] + "\t\t" + values[3]
                                                 + "\n\nDo these values look correct?", "Value Confirmation", MessageBoxButtons.YesNoCancel);
                if (r == DialogResult.Cancel)
                {
                    Environment.Exit(0);
                }
                accepted = r == DialogResult.Yes;
            }

            Pusher          = new System.Timers.Timer();
            Pusher.Elapsed += (s, a) => TryWrite(s, a, b);
            Pusher.Interval = 1000 * 60 * 1; //1 minute interval

            Adjutant           = new System.Timers.Timer();
            Adjutant.Elapsed  += StartTrying;
            Adjutant.Interval  = (DateTime.Today.AddDays(1) - DateTime.Now).TotalMilliseconds; //runs midnight tomorrow
            Adjutant.AutoReset = false;
            Adjutant.Start();


            TryWrite(null, null, b);

            do
            {
                signaled = waitHandle.WaitOne();
            } while (!signaled);
        }