Moscow at night

Advertisements
By Michael Haephrati מיכאל האפרתי Posted in Uncategorized

How to play with the ‘date’ taken’ attribute of photos

Original article I have published at Code Project

http://www.codeproject.com/Articles/792931/Date-time-batch-changer-for-photos-and-other-files

Source code

Executable to download

Background

I recently looked for photos and videos of an important event and couldn’t understand why I can’t find any video files, even though I recalled that my wife and my daughter took both photos and videos…

I then realized that our still camera (Nokia D5000) and camcorder (Sony) are both set up with the wrong time, each with a different wrong time… One was 7 hours and 36 minutes earlier and the other was 3 hours later. That was the reason for the confusion, and I spent a lot of time checking backups, etc. thinking my precious files were somehow deleted.  I calculated the correct times of both video and photo files, adjusting their time stamp and happily found out that both occurred within the same time frame, so everything was OK. I then setup the time of the camcorder and the camera to the correct time. and looked for a way to fix the incorrect time stamps of my photos and video files. That is when I decided to program such tool myself…

Introduction

Even though there can be many occasions in which a program like the one I am about to introduce, can be useful, I originally developed it for the purpose of adjusting wrong time stamp of photos and videos, which are a result of incorrect settings or timezone in the camcoder or camera.  The idea is to define the following:

  • Path – where to look (will bring a path dialog box where the user can type or choose the start path to search. For example: c:\ or c:\users\myuser\documents\

  • Query – what to look for (for example all files ending with .AVI, or all files within a certain date, or files which contain a certain string in their name).

  • Date related attributes to apply to– which can be either:

    • Date Created
    • Date Last Modified
    • Date Last Accessed
    • Date Taken
  • Requested change – which can be either:

    • Fixed date and time, for example: 7.7.2014 01:00
    • Relative change of currently stamped date and time, for example: 7 and a half hours earlier (Dec 12, 2014 12:31AM will be adjusted to: Dec 11, 2014 5:01PM)

The Building Blocks

Searching for files based on a given criteria

Our application allows you to either state the extension of files searched for, the name (or part of it) but also to process only files having a certain date/time stamp. I will elaborate about the various attributes files have, which are date/time related in the next section, however, for the simplicity of this article, our program changes all of these attribute at once. A ComboBox is used to allow the user to make the selection among the above options.

Changing a file’s date/time related attributes

There are several attributes which are relevant for our goal, among them:

  • Date Created- The date and time in which the file was first created.
  • Date Modified- The date and time in which the file was last modified.
  • Date Accessed – The date and time in which the file was last accessed.

for photos there is another important attribute: Date Taken. That is the date and time a photo was taken.

For the purpose of the article, “photos” are identified by their extension and include .jpg and .nef (Nokia) photos, but that of course can and should be enhanced.


The Date Taken Property

The Date Taken property appears as one of the optional columns Windows Explorer allows to choose. This property is only valid for photos. Unlike the other date related file properties, this one is taken from the EXIF (Exchange Image File format) of the image file.

In order to read and manipulate the EXIF of the file, I have used exif.cpp and exif.h written by Davide Pizzolato, which based his work on jhead-1.8 by Matthias Wandel.

When a file is identified as a photo, getTakenXap is called:

Then the current “Date Taken” attribute value is used to call parseXapTime.

Calculating date and time differences

If you look at web sites like this one, you can check the possibilities covered in the code, for example changing the date/time stamp of a file so it will show 7 and a half hours backward.

To do such calculations from an application, we can use CTime for storing the time, and CTimeSpan for the calculations.

CTime

The CTime class is used to hold an absolute time and date.

Microsoft provides 7 different constructors for the CTime class which amongst others, allows you to do the following:

  1. Create a time class using a Standard Library time_t calender time.
  2. Create a time class using a dos date and time.
  3. Create a time class using a Win32 SYSTEMTIME or FILETIME
  4. Create a time class using individual entries for year, month, day, hour, minute, and second.

By incorporating the ANSI time_t data type, the CTime class provides all the functionalities discussed above in section 1. It also has methods to get the time in SYSTEMTIME or FILETIME or GMT format.

In addition this class also overloads the +, -, = , ==, <, <<, >> operators to provide many more useful features.

You can find the definition of CTime class in afx.h header file and it is as following:

The Process

First you select the search creteria, and / or a folder where you wish to start…

Alternatively, files can be just dragged and dropped to the dialog box.

Note: in this version only one file can be dragged, but that will be fixed later.

For the purpose of this article, I have created a folder named “test” and copied there many files, and folders. These files are both photos (.jpg) and non photos (.txt).

After the files are found based on the search criteria, selected or dragged and dropped, the process starts. Each file is checked and its date/time attributes are changed.

  • If a certain date and time are requested, the change takes into consideration the local time zone and whether day light savings is on or off.

}

  • An “Undo” button allows reversing any change.
  • The log of the changes that have taken place is displayed on screen, along with the date/time before and after the process.
  • The user can check via check boxes which dates should be changed.
  • The dates include the “Date Taken” attribute which is unique for photos (such as .jpg and camera specific files such as .NEF files (Nikon camera), etc. That is done via accessing the EXIF of the graphic file.

User Interface

As part of my efforts to make my small application user friendly and easy to use, I have done the following:

  • Keeping last entered values:

    Since there are two types of input from the user: a fixed date / time and a relative time (number of hours), which are indicated by setting a Combo box to either “Relative Date” or “Fixed Date”, it is important that when the user switches between the two, the last value entered will be show. For example, if you entered the fixed date “2000/01/01” and then entered 8:30 as a Relative Date, when you select “Fixed Date” again, the last value “2000/01/01” should be shown, and when switching back to Relative Date, the last relative value, “8:30” should be shown as well.

  • Allowing flexible data entry

    It should be possible to enter the following as a fixed date:

    • 2000/01/01 00:00:00
    • 2000/01/01 00:00
    • 2000/01/01

          It should be possible to enter a relative time in various ways:

  • 10 (means 10 hours forward)
  • -5 (means 5 hours backward)
  • 10:30 (means 10 and a half hours forward)

and so on…

  • Error handling

    In case there is an error, such as a file being locked, the log entry of this specific file is marked as “Failed” and the process continues.

Code Signing

As I am involved with large scale projects, my software venture purchases a Code Signing Certificate from Verisign (they cost $499 a year, and are suitable also for Kernel drivers).

To sign an executable, I use a tool named kSign by Commodo.

The difference between signing your executables and not signing them can be explained by the warrning your customer will get when trying to download a non signed executable.

and also:

But if your executable is signed, the user will get this message:

Which is better. Obtaining a Verisign certificate means that your identity (or your company’s identity) are fully verified.

Final Notes

Thanks to Aha-Soft for the icon used for the demo application. Copyright © 2000-2014 Aha-Soft

If you find bugs, please feel free to send me the revised source code Smile | :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Sending Text Messages from an iOS App

Introduction

This article explains how to add the capability of sending text (SMS) messages from a desktop application.

Background

The article focuses on an implementation using MFC / C++. While looking for a reliable and cheap solution for sending SMS messages programmatically, I came across a company named CardBoardFish which covers 150 countries and provides an easy to use, yet powerful SDK for interfacing from any web site, mobile phone, or desktop application, covering most platforms and development environments. Unfortunately, among the code samples in their web site, there aren’t any C++ samples, so I decided to develop my own C++ implementation.

Sending SMS Messages Programmatically

Most applications and web sites used to send SMS messages as part of their scope or among other functionalities (i.e., sending alerts, etc.) use one of the following methods:

HTTP Web Service –  requires using HTTP “GET” method to send a given Web Service a command, using an API, which contains the credentials, parameters, and the text for this message.

Email to SMS  – uses the SMTP protocol to allow sending an email in a unique format, which encodes all required parameters (credentials, sender, receiver, etc.) as part of an email.

This article focuses on the first method, using a Web Service.

The API

The following table lists all parameters that can (or should) be sent to the Web Service:

image1

Using the code

The code in this article was developed in MFC / C++ using Visual Studio 2010 Ultimate. I also used Cheng Shi‘s HTTPClient (thanks Cheng!).

In order to use the code for your own application, it is advised to read the specifications for the SDK named HTTPSMS. Secondly, you need to open an account and obtain your user name and password, which can be hardcoded in the source code, or entered during runtime.

The SendSMS application

image2

The main functionality of our application is obviously sending an SMS, which is done in the following function:

// SendSms – by Michael Haephrati

BOOL SendSms(CString From, CString CountryCode, CString To,CString Message,CString *Status)

// From – the ID or number you are sending from. This is what will appear at the recipient’s cellphone.

// CountyCode – the code of the country you are sending the SMS to (for example: 44 is for the UK

as, etc.
// Message – is the message you are sending, which can be any multi lingual text
// The statu

// To – is the number you are texting to, which should not contain any leading zeros, spaces, com

ms returned would be either a confirmation number along with the text “OK”, which means that the message

    // was delivered, or an error code. 
{
    BOOL result=FALSE;

equest+=user; // user name
request+=L”&P=”;
request+=pass; // password
r

    wstring user=L"PLACE_YOUR_USERNAME_HERE",pass=L"PLACE_YOUR_PASSWORD_HERE",request=L"";
    // 
    request=L"http://sms1.cardboardfish.com:9001/HTTPSMS?S=H&UN=";
    
request+=L"&DA="; 
    request+=(wstring)(CountryCode+To); // country code
    request+=L"&SA="; 
    request+=(wstring)From; // From (sender ID)
    request+=L"&M=";
    CString EncodedMessage; // Message
    
    CString ccc;

ssage is encoded as opposed to plain text

    EncodedMessage=ConvertHex(Message)+ConvertHex( L" here you can place your marketing piech, website, etc.");
    
    request+=(wstring)EncodedMessage; // Message to send

    request+=L"&DC=4";
    // Indicating that this m

e

Now we handle the HTTP “GET” request:

WinHttpClient client(request);

nt.SendHttpRequest(L”GET”,true);
// G

cli

eet the response

sponseHeader = client.GetResponseHeader();
wstring httpR

    wstring httpR
eesponseContent = client.GetResponseContent();

turn result;
}

    *Status=httpResponseContent.c_str();

Other Services

I have tested the services of CardBoardFish, which I used for the attached source code. They provide their own code samples here, but these don’t include c++, which I why I wrote the test application attached to this article.

I recently tested another service they provide which is verifying mobile numbers before sending the text messages. I didn’t include this functionality because I found it to be too slow, and also it doesn’t cover some countries, among them… USA.

I found another alternative service provider : http://www.clickatell.com so there are several options to choose from.

Further Reading

Please refer to another article of mine, this time explaining how to do the same using iOS (iPhone / iPad).

Target Eye Revealed – part 6

This new article contains another portion of the Target Eye Monitoring System’s source code along with the secret behind the method used by Target Eye to hide its files. Target Eye was able to hide its own files along with all files collected from the target machine, prior to sending it to its operator. The article explains how these files are hidden, along with exposes how to reveal these hidden files.

The default UI

Target Eye uses a simple (and yet unique) mechanism  to hide files but the trick will work on most new Windows systems (including Windows 8) that because the only option to reveal these hidden files is not part of the default user interface of the Windows Files Explorer, so even if the “Show Hidden Items” is checked, the Target Eye hidden files will not be revealed.

You can read more and browse further parts of the Target Eye source code in the following articles:

1.  The first article is about Target Eye’s Auto Update mechanism, and how it is capable of checking for updates, downloading them when there are, installing them and running them instead of the old version currently running, all of the above, with no end-user intervention.

2. The second article was about the Target Eye’s screen capturing mechanism, and how compact JPG files are created combining a reasonable image quality and a small footprint.

3. The third article was about the Shopping List mechanism.

4. The forth article is about Keyboard capturing.

5.The fifth article deals with the packaging used to let our Secret Agent in. In other words, how Target Eye can be used to wrap it with what we refer to as “cover story”

6. The Sixth article explains how files are hidden and when, along with exposing how to reveal these hidden files.

סדרת מאמרים אודות תוכנת Target Eye

Here is a list of articles I have written about Target Eye Monitoring System

Target Eye Revealed – part 1

http://www.codeproject.com/Articles/310530/Target-Eye-Revealed-part-1-Target-Eyes-Unique-Auto

Target Eye Revealed – part 2

http://www.codeproject.com/Articles/460498/Target-Eye-Revealed-part-2-Target-Eyes-Screen-Capt

Target Eye Revealed – part 3

http://www.codeproject.com/Articles/461344/Target-Eye-Revealed-part-3-The-Shopping-List-Mecha

Target Eye Revealed – part 4

http://www.codeproject.com/Articles/635134/Target-Eye-Revealed-part-4-Keyboard-Capturing

Target Eye Revealed – part 5

http://www.codeproject.com/Articles/635384/Target-Eye-Revealed-The-Cover-Story

Target Eye Revealed – part 6

http://www.codeproject.com/Articles/785450/Target-Eye-Revealed-part-6-File-Hiding