Tuesday, January 4, 2011

Randomize picture names

The following is a console application written in C# for randomizing names of jpg-files in the current directory and all sub directories. I made it so my mother can make pictures appear in random order on the digital picture frame I gave her last Christmas as it lacked that feature.

All output is in Swedish.
Download binary
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace se.gotling.tools
{
    class RandomizeFileNames
    {
        private static string extension = ".jpg";

        static void Main(string[] args)
        {
            string fullPath = System.Reflection.Assembly.GetAssembly(typeof(RandomizeFileNames)).Location;
            string directory = Path.GetDirectoryName(fullPath);

            Console.WriteLine("Katalog: {0}\n" ,directory);
            
            string[] fileNames = Directory.GetFiles(directory, "*" + extension, SearchOption.AllDirectories);
            if (fileNames.Length > 0)
            {
                Console.WriteLine("Hittade {0} filer med filändelsen {1}\n", fileNames.Length, extension);
            }
            else
            {
                Console.WriteLine("Inga filer hittades med filändelsen {0}\nTrycka på valfri tangent för att avsluta", extension);
                Console.ReadKey(true);
                return;
            }
            
            Console.WriteLine("Tryck \"r\" för att slumpa fram nya filnamn\n");
            if(!Console.ReadKey(true).Key.Equals(ConsoleKey.R))
            {
                Console.WriteLine("Avbröt ändring av filnamn. Trycka på valfri tangent för att avsluta");
                Console.ReadKey(true);
                return;
            }

            foreach (string fileName in fileNames)
            {
                string filePath = Path.GetDirectoryName(fileName);
                while (true)
                {
                    string newFileName = filePath + Path.DirectorySeparatorChar + Path.GetRandomFileName().Split('.')[1] + extension;
                    if (!File.Exists(newFileName))
                    {
                        File.Move(fileName, newFileName);
                        Console.WriteLine("Före: {0}\t Efter: {1}", fileName.Remove(0, directory.Length + 1), newFileName.Remove(0, directory.Length + 1));
                        break;
                    }
                }
                
            }
            Console.WriteLine("\n\nFärdig! Trycka på valfri tangent för att avsluta");
            Console.ReadKey(true);
        }
    }
}

Tuesday, March 9, 2010

Customize Touch in Internet Explorer 8

I'm currently working on a project involving a web based system controlled by touch. Internet Explorer 8 will be used for it running in kiosk-mode on one single machine.

A problem I ran into was that IE8 has some new clever feature that opens links in a new tab if they are dragged a few pixels using touch. Flicks I think they call it. This caused pages to be accidentally open in tabs if the user didn't touch the screen right.

Nowhere on the Internet could I find any way to disable this feature. So I started digging in the Windows registry. There I found the following key:

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Touch

That only contained one value, FlickEducatorInfo, which wasn't what I was looking for.

So I searching for the reg-key on Google and found two results, both some forum posts in French. There some user had dropped a lot of info from Hijack This or some similar tool. I searched for "Touch" on the page and found the same key as above but it had an additional value:

"TouchDragBuffer"= 0x0000000007 (7)

Changed that to:
"TouchDragBuffer"= 0x0000001000 (4096)

Worked perfectly! Now the user that can't point straight needs to drag the link more than a screen-length away before a new tab is opened.

Would be nice if there were touch settings in Internet Explorer though. Maybe IE9?