int main ( int argc, char *argv[] ) { FILE *fp; time_t ltime; // // check the number of parameters // if (argc != 3) { PrintUsage (); return -1; } // // open the TIME file, if not exists, return // fp = fopen (argv[2], "r+"); if (fp == NULL) { return 0; } // // get time and date from file // if (GetDateTime (fp, <ime) != 0) { fclose (fp); return -1; } // // close the TIME file // fclose (fp); // // open the PE file // fp = fopen (argv[1], "r+b"); if (fp == NULL) { printf ("Error: Cannot open the PE file!\n"); return -1; } // // set time and date stamp to the PE file // if (SetStamp (fp, ltime) != 0) { fclose (fp); return -1; } printf ("Set Date/Time Stamp to %s", ctime (<ime)); // // close the PE file // fclose (fp); return 0; }
//---------------------------------------------------------------------------------------- // Init //---------------------------------------------------------------------------------------- ErrorCode CZPLinkResource::Init( IDataLink* iDataLink, const URI& uri) { NameInfo nameInfo; PMString formatName; uint32 fileType; ErrorCode errorCode = iDataLink->GetNameInfo (&nameInfo, &formatName, &fileType); mId = uri; if (errorCode == kSuccess) { uint64 storedSize = 0; uint64 storedTime = 0; IDataLink::StateType calculatedType = IDataLink::kLinkNormal; IDataLink::StateType oldStoredType = iDataLink->GetStoredState (&storedSize, &storedTime); uint64 modTime = 0; // Check if times are consistent or close enough. ResourceStamp resourceStamp; if (oldStoredType != IDataLink::kEmbedded) { uint64 currentSize = 0; uint64 currentTime = 0; bool16 fileExists = GetCurrentTimeAndSizeFromURI (currentTime, currentSize); if (fileExists) { #ifdef DEBUG bool hasStamp = #endif ConstructStampFromURI (resourceStamp); ASSERT (hasStamp); if (storedSize != currentSize || TimeStampsCloseEnough (storedTime, currentTime) == false) { //ASSERT (oldStoredType == IDataLink::kLinkOutOfDate); ConstructStampFromTimeSize (storedTime, storedSize, resourceStamp); modTime = storedTime; if (oldStoredType != IDataLink::kLinkOutOfDate) { calculatedType = IDataLink::kLinkOutOfDate; iDataLink->SetStoredState (nil, nil, calculatedType); } } else { modTime = currentTime; } } else { // File does not exist. // the persisted type can easily be different from the current type. calculatedType = IDataLink::kLinkMissing; ConstructStampFromTimeSize (storedTime, storedSize, resourceStamp); modTime = storedTime; } } else { // Embedded calculatedType = IDataLink::kEmbedded; ConstructStampFromTimeSize (storedTime, storedSize, resourceStamp); modTime = storedTime; } SetSize(storedSize); // the persisted type can easily be different from the current type. // commenting out assert. dstephens 06/06/2007 //ASSERT (calculatedType == oldStoredType); ILinkResource::ResourceState state = (oldStoredType == IDataLink::kLinkMissing) ? kMissing : kAvailable; // Set attributes SetFormatType(formatName); SetModTime(modTime); SetStamp(resourceStamp); SetState(state); // Embeded if (oldStoredType == IDataLink::kEmbedded) { InterfacePtr<ILinkObjectReference> iOldObjectRef (iDataLink, UseDefaultIID ()); if (iOldObjectRef != nil && iOldObjectRef->GetUID () != kInvalidUID) { InterfacePtr<IStoreInternal> iStoreInternal (mDB, iOldObjectRef->GetUID (), IID_ISTOREINTERNAL); // Delete old stored data UID storedUID = iStoreInternal->GetStoredUID (); if (storedUID != kInvalidUID && mDB->IsValidUID (storedUID)) { //iStoreInternal->SetStoredUID (kInvalidUID); mStoreState = kEmbedded; SetState(kAvailable); mStoredResourceUID = storedUID; } } } } return errorCode; }