Monday, March 11, 2013

Xinmapper2013R1

I have updated my XBOX 360 controller project Xinmapper yet again, it now features a 1/3rd reduction in size from the original release. Oddly enough small code improvements can shrink the size of the executable by that much! https://sourceforge.net/projects/xinmapper/files/?source=navbar

Monday, December 17, 2012

Well I have updated Xinmapper for 2013, for those interested it is intended to be a useful library for implementing Xbox 360 controller functionality. More information here: https://sourceforge.net/projects/xinmapper/?source=directory Please check-out the subversion if you are interested, it now includes build help images!

Friday, March 16, 2012

Java, java, java...

doing my classwork in java...
I must say it really sucks as a language, I personally despise it.  I think it should never have been created, or at least created differently.  If you can wade through the complete crap the language throws at you, you might get a high-paying job, but I don't know if it would be worth it...

Java sucks!  It really is like a retarded version of C#, but it runs on more things.

Monday, February 6, 2012

More freelance experience

I think you'll find this tip quite handy if you ever need to download all of the emails from a GMAIL inbox.

Don't use POP3, use IMAP!!
Google has a problem with their POP3, it will only let you access part of your entire messages!
It simply doesn't handle 1000 messages like IMAP does, oh and IMAP has great SSL.

It's easy to use in C#, I used the ActiveUp mail library and provided a nice GUI for my client so he could do his parsing.


As you might have guessed it inserts the parsed data into an excel spreadsheet for the client.

Monday, December 12, 2011

C++ and Boost thread.

This is a class I think someone may find very entertaining one day, it fits a modest need to do something asynchronously, why not take a look?

If you want to use it for something it will need to be adjusted slightly as it is taken from my project Xinmapper hosted on sourceforge.

[code]

#pragma once
#include "stdafx.h"
#include "Mapper.h"
#include "XInputTranslater.h"
#include "XInputBoostMouse.h"
#include "PlayerInfo.h"

class InputPoller
{
 typedef boost::mutex::scoped_lock lock;
public:
 const int THREAD_DELAY;
 boost::shared_ptr<boost::thread> thread;
protected:
 volatile bool isThreadRunning;
 volatile bool isStopRequested;
 XINPUT_STATE local_state;
 boost::mutex stateMutex;
 
 PlayerInfo *p;
 Mapper *m;
 XInputTranslater *t;
 XInputBoostMouse *mse;

protected://member functions
 void startThread()
 {
  if( ! this->isThreadRunning )
  {
   this->isStopRequested =(false);
   this->isThreadRunning =(true);
   this->thread = boost::shared_ptr<boost::thread>
    (new boost::thread(boost::bind(&InputPoller::workThread,this)));
  }
 }

 void requestStop(){
  if( this->thread != nullptr ){
   if(! this->isThreadRunning )
    return;
   this->isStopRequested =(true);
  }
 }

 void stopThread(){
  if(this->thread != nullptr){
   if(! this->isThreadRunning )
    return;
   this->isStopRequested =(true);
   this->thread->join();
   this->isThreadRunning =(false);
  }
 }
  
 virtual void workThread()
 {
  while( ! this->isStopRequested )
  {
   DWORD error = XInputGetState(p->player_id, &local_state);
   if( error != ERROR_SUCCESS )
    break;
   mse->ProcessState(local_state);
   m->ProcessActionDetails( t->ProcessState(local_state) );
   Sleep(THREAD_DELAY);
  }
  this->isThreadRunning = false;
 }

public://public member functions
 InputPoller(PlayerInfo *playerInfo, Mapper *mapper, XInputTranslater *trans, XInputBoostMouse *mouse)
  : THREAD_DELAY(10), p(playerInfo), m(mapper), t(trans), mse(mouse)
 {
  isThreadRunning = false;
  isStopRequested = false;
  lock(stateMutex);
  memset(&local_state,0,sizeof(XINPUT_STATE));
 }
  
 //This function does block when it is called by default.
 virtual ~InputPoller(){
  if( this->thread != nullptr ){
   this->isStopRequested = true;
   this->thread->join();
  }
 }

 bool Start()
 {
  this->startThread();
  return this->isThreadRunning;
 }

 bool Stop()
 {
  this->stopThread();
  return this->isThreadRunning;
 }
 bool IsRunning()
 {
  return this->isThreadRunning;
 }
 bool IsControllerConnected()
 {
  XINPUT_STATE ss = {0};
  return XInputGetState(p->player_id, &ss) == ERROR_SUCCESS;
 }
};
[/code]
Also you may notice I've made good use of protected members as well as virtual functions.  Happy coding!

Saturday, October 22, 2011

C# Web Browser Automation

There are tons of approaches to most programming tasks, and web browser automation is no exception.
But, with C# there are some facilities provided to make it a lot easier than you may at first suspect.

The WebBrowser class:
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx

The webbrowser class is basically Microsoft IE embedded in your application, not a bad thing if you need a webbrowser!

Inside the webbrowser class is a "Document" property composed of multiple HtmlElements,
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.document.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.htmlelement.aspx

Now, the easiest way to use this to our advantage is to use Google chrome, and right click on the element you want to work with (on the browser page) and select "inspect element".

Many times elements include an "id=" section, which be used like so:

HtmlElement he = WebBrowser.Document.GetElementById("loginbutton");

and these elements can be used to our advantage:

he.InvokeMember("click");
he.InnerText = "Something";

This post is by no means complete but does provide a very simple way to easily get started !

Monday, August 22, 2011

A more durable screen capture class!

Here's a more durable (not exactly performance-tuned) screen capture class that I think someone will be pleased to find someday, it also does quality reduction (and thus file-size) for the Jpeg file format.  Pretty neat.

GetScreen.cs
[code]
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.IO;

namespace ScreenCapture
{
    
    public class GetScreen
    {
        private Graphics gfx;
        private Bitmap bmp;
        private Point zero;
        private Size resolution;
        private Size imgSz;

        public GetScreen()
        {
            zero = new Point(0, 0);
            resolution = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                Screen.PrimaryScreen.Bounds.Height,
                PixelFormat.Format32bppArgb);
            gfx = Graphics.FromImage(bmp);
            imgSz = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
        }
        ~GetScreen()
        {
            bmp.Dispose();
            gfx.Dispose();
        }
        public Bitmap GetWholeScreen()
        {
            gfx.CopyFromScreen(zero, zero, resolution);
            return new Bitmap(bmp, imgSz);
        }
        public Bitmap GetImageCopy(Point topLeft, Size widthHeight)
        {
            gfx.CopyFromScreen(zero, zero, resolution);
            return bmp.Clone(new Rectangle(topLeft, widthHeight), PixelFormat.DontCare);
        }
        public void SaveBitmapAsJpeg(Bitmap someBitmap, long qualityPercentage, string fileName)
        {
            if (someBitmap == null || fileName == null)
            {
                throw new ArgumentNullException();
            }
            if (qualityPercentage > 100 || qualityPercentage < 0)
            {
                throw new ArgumentException("Argument qualityPercentage was out of bounds.  0-100 is supported.");
            }
            ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
            ImageCodecInfo ici = null;
            foreach (ImageCodecInfo codec in codecs)
            {
                if (codec.MimeType == "image/jpeg")
                {
                    ici = codec;
                    break;
                }
            }
            EncoderParameters ep = new EncoderParameters();
            //0 = lowest quality, 100 = highest.
            ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)qualityPercentage);
            someBitmap.Save(fileName, ici, ep);
        }
        public void SaveBitmapAsJpeg(Bitmap someBitmap, long qualityPercentage, Stream st)
        {
            if (someBitmap == null || st == null)
            {
                throw new ArgumentNullException();
            }
            if (qualityPercentage > 100 || qualityPercentage < 0)
            {
                throw new ArgumentException("Argument qualityPercentage was out of bounds.  0-100 is supported.");
            }
            ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
            ImageCodecInfo ici = null;
            foreach (ImageCodecInfo codec in codecs)
            {
                if (codec.MimeType == "image/jpeg")
                {
                    ici = codec;
                    break;
                }
            }
            EncoderParameters ep = new EncoderParameters();
            //0 = lowest quality, 100 = highest.
            ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)qualityPercentage);
            someBitmap.Save(st, ici, ep);
        }

    }
}
[/code]


I also had time to make a demo using the class, it wasn't specifically for the blog but it may be interesting for a spare minute or so.

http://www.mediafire.com/?v0lhcfznb1oz0wt