Search code examples
c#visual-studio-2012timestampadd-invisual-studio-addins

Visual Studio -> Copy WebSite -> RemoteSite1.xml -> What is TimeHigh / TimeLow?


I'm currently trying to program an add-in that mocks Visual Studio's copy website tool. This is because Microsoft's tool has some behavior I want to change.

But I want it to be as close as possible to the default tool. The default tool is using cache files to identify changes and determines solutions for conflict situations.

There are following corresponding files in the websitecache-directory (c:\Users[Username]\AppData\Local\Microsoft\WebsiteCache[Website-Name]): PublishState.xml RemoteSite1.xml

In PublishState.xml the file-names are listet:

<LocalFile>
    <FileId>2828</FileId>
    <RelativePath>Test.aspx</RelativePath>
</LocalFile>

In RemoteSite1.xml the time-stamps (?) or whatever is stored:

<FileModifiedTimes>
    <FileId>2828</FileId>
    <LocalTimeHigh>30429237</LocalTimeHigh>
    <LocalTimeLow>-47918156</LocalTimeLow>
    <RemoteTimeHigh>30429237</RemoteTimeHigh>
    <RemoteTimeLow>-47918156</RemoteTimeLow>
</FileModifiedTimes>

I made a few files on specific moments and documented the date and values (german date format = dd.MM.yyyy hh:mm):

Date (file-creation) LocalTimeHigh  LocalTimeLow
24.02.2015 14:15     30429236       116508521
24.02.2015 14:25     30429237       1248929358
24.02.2015 14:27     30429237       -1558459195
24.02.2015 14:30     30429237       -47918156

My attempt was to determine a correlation between the date and the values, but I can't see any correlation. I also tried to google if "TimeHigh" or "TimeLow" does mean anything specific, but also wasn't able to find a clue nor solution.

My question: How can I convert the TimeHigh/TimeLow-values into datetime values and contravise?


Solution

  • It's a serialization of the System.Runtime.InteropServices.ComTypes.FILETIME struct.

    You can convert to DateTime with a snippet like this:

    using System.Runtime.InteropServices.ComTypes;
    
    FILETIME filetime = new FILETIME {
        dwHighDateTime = 30429237,
        dwLowDateTime = 116508521
    };
    
    long combined = ((long)filetime.dwHighDateTime << 32) | filetime.dwLowDateTime;
    DateTime dt = DateTime.FromFileTimeUtc(combined); 
    // or use FromFileTime() for local timezone
    
    long timestamp = dt.ToFileTimeUtc();
    FILETIME backAgain = new FILETIME {
        dwHighDateTime = (int)(timestamp >> 32), // drop lower 32 bits
        dwLowDateTime = (int)(timestamp & 0xffffffff)
    };