private static bool SetCombinedDateTime(ref DateTime newDT, DateTime currentDT, ContentFieldType fieldType, bool dateOnly) { bool result = true; switch (fieldType) { case ContentFieldType.DateTime: if (dateOnly) { newDT = new DateTime( newDT.Year, newDT.Month, newDT.Day, currentDT.Hour, currentDT.Minute, currentDT.Second); } break; case ContentFieldType.Date: newDT = new DateTime( newDT.Year, newDT.Month, newDT.Day, currentDT.Hour, currentDT.Minute, currentDT.Second); break; case ContentFieldType.Time: newDT = new DateTime( currentDT.Year, currentDT.Month, currentDT.Day, newDT.Hour, newDT.Minute, newDT.Second); break; default: result = false; break; } return(result); }
public static int GetValueW([MarshalAs(UnmanagedType.LPWStr)] string fileName, int fieldIndex, int unitIndex, IntPtr fieldValue, int maxLen, int flags) { GetValueResult result; ContentFieldType fieldType = ContentFieldType.NoMoreFields; GetValueFlags gvFlags = (GetValueFlags)flags; callSignature = String.Format("ContentGetValue '{0}' ({1}/{2}/{3})", fileName, fieldIndex, unitIndex, gvFlags.ToString()); try { string fieldValueStr; // TODO: add - comments where .NET plugin interface differs from TC result = Plugin.GetValue(fileName, fieldIndex, unitIndex, maxLen, gvFlags, out fieldValueStr, out fieldType); if (result == GetValueResult.Success || result == GetValueResult.Delayed || result == GetValueResult.OnDemand) { ContentFieldType resultType = result == GetValueResult.Success ? fieldType : ContentFieldType.WideString; (new ContentValue(fieldValueStr, resultType)).CopyTo(fieldValue); } // !!! may produce much trace info !!! TraceCall(TraceLevel.Verbose, String.Format("{0} - {1}", result.ToString(), fieldValueStr)); } catch (Exception ex) { ProcessException(ex); result = GetValueResult.NoSuchField; } return(result == GetValueResult.Success ? (int)fieldType : (int)result); }
public static int EditValue(IntPtr parentWin, int fieldIndex, int unitIndex, int fieldType, IntPtr fieldValue, int maxLen, int flags, [MarshalAs(UnmanagedType.LPStr)] string langIdentifier) { SetValueResult result; ContentFieldType fldType = (ContentFieldType)fieldType; EditValueFlags evFlags = (EditValueFlags)flags; callSignature = String.Format("ContentEditValue ({0}/{1}/{2})", fieldIndex, unitIndex, evFlags.ToString()); try { TcWindow tcWin = new TcWindow(parentWin); ContentValue value = new ContentValue(fieldValue, fldType); string strValue = value.StrValue; result = Plugin.EditValue(tcWin, fieldIndex, unitIndex, fldType, ref strValue, maxLen, evFlags, langIdentifier); if (result == SetValueResult.Success) { value.StrValue = strValue; value.CopyTo(fieldValue); } TraceCall(TraceLevel.Info, String.Format("{0} - {1}", result.ToString(), value.StrValue)); } catch (Exception ex) { ProcessException(ex); result = SetValueResult.NoSuchField; } return((int)result); }
public ContentValue(IntPtr ptr, ContentFieldType fieldType) { FieldType = fieldType; strValue = null; if (ptr != IntPtr.Zero) { switch (fieldType) { case ContentFieldType.Numeric32: strValue = Marshal.ReadInt32(ptr).ToString(CultureInfo.InvariantCulture); break; case ContentFieldType.Numeric64: strValue = Marshal.ReadInt64(ptr).ToString(CultureInfo.InvariantCulture); break; case ContentFieldType.NumericFloating: Double[] dv = new Double[1]; Marshal.Copy(ptr, dv, 0, 1); strValue = dv[0].ToString(CultureInfo.InvariantCulture); break; case ContentFieldType.Date: Int16[] date = new Int16[3]; Marshal.Copy(ptr, date, 0, 3); // convert to standard short date format ("d") strValue = (new DateTime(date[0], date[1], date[2])).ToString(CultureInfo.InvariantCulture); break; case ContentFieldType.Time: Int16[] time = new Int16[3]; Marshal.Copy(ptr, time, 0, 3); // convert to standard long time format ("T") strValue = (new DateTime(1, 1, 1, time[0], time[1], time[2])).ToString(CultureInfo.InvariantCulture); break; case ContentFieldType.Boolean: strValue = (Marshal.ReadInt32(ptr) != 0).ToString(); break; case ContentFieldType.MultipleChoice: case ContentFieldType.String: strValue = Marshal.PtrToStringAnsi(ptr); break; case ContentFieldType.DateTime: // convert to General date/long time format ("G") strValue = DateTime.FromFileTime(Marshal.ReadInt64(ptr)).ToString(CultureInfo.InvariantCulture); break; case ContentFieldType.WideString: strValue = Marshal.PtrToStringUni(ptr); break; } } }
public TcFieldCreateDateTime(ContentFieldType mode) { _mode = mode; var opt = mode switch { ContentFieldType.Date => SupportedFieldOptions.SubstDate, ContentFieldType.Time => SupportedFieldOptions.SubstTime, ContentFieldType.DateTime => SupportedFieldOptions.SubstDateTime, _ => throw new ArgumentException("invalid enum value", paramName: nameof(_mode)) }; Options = SupportedFieldOptions.Edit | opt; }
public static int SetValueW([MarshalAs(UnmanagedType.LPWStr)] string fileName, int fieldIndex, int unitIndex, int fieldType, IntPtr fieldValue, int flags) { SetValueResult result; ContentFieldType fldType = (ContentFieldType)fieldType; SetValueFlags svFlags = (SetValueFlags)flags; callSignature = String.Format("ContentSetValue '{0}' ({1}/{2}/{3})", fileName, fieldIndex, unitIndex, svFlags.ToString()); try { ContentValue value = new ContentValue(fieldValue, fldType); result = Plugin.SetValue(fileName, fieldIndex, unitIndex, fldType, value.StrValue, svFlags); TraceCall(TraceLevel.Info, String.Format("{0} - {1}", result.ToString(), value.StrValue)); } catch (Exception ex) { ProcessException(ex); result = SetValueResult.NoSuchField; } return((int)result); }
public override SetValueResult SetValue(string fileName, int fieldIndex, int unitIndex, ContentFieldType fieldType, string fieldValue, SetValueFlags flags) { if (String.IsNullOrEmpty(fileName) && fieldIndex < 0) // change attributes operation has ended { return(SetValueResult.NoSuchField); } if (String.IsNullOrEmpty(fieldValue)) { return(SetValueResult.NoSuchField); } SetValueResult result = SetValueResult.NoSuchField; DateTime created = DateTime.Parse(fieldValue); bool dateOnly = (flags & SetValueFlags.OnlyDate) != 0; if (Directory.Exists(fileName)) { DirectoryInfo dirInfo = new DirectoryInfo(fileName); if (SetCombinedDateTime(ref created, dirInfo.CreationTime, fieldType, dateOnly)) { Directory.SetCreationTime(fileName, created); result = SetValueResult.Success; } } else if (File.Exists(fileName)) { FileInfo fileInfo = new FileInfo(fileName); if (SetCombinedDateTime(ref created, fileInfo.CreationTime, fieldType, dateOnly)) { File.SetCreationTime(fileName, created); result = SetValueResult.Success; } } else { result = SetValueResult.FileError; } return(result); }
public static int GetSupportedField(int fieldIndex, IntPtr fieldName, IntPtr units, int maxLen) { ContentFieldType result = ContentFieldType.NoMoreFields; callSignature = String.Format("ContentGetSupportedField ({0})", fieldIndex); try { string fieldNameStr, unitsStr; result = Plugin.GetSupportedField(fieldIndex, out fieldNameStr, out unitsStr, maxLen); if (result != ContentFieldType.NoMoreFields) { if (String.IsNullOrEmpty(fieldNameStr)) { result = ContentFieldType.NoMoreFields; } else { TcUtils.WriteStringAnsi(fieldNameStr, fieldName, maxLen); if (String.IsNullOrEmpty(unitsStr)) { units = IntPtr.Zero; } else { TcUtils.WriteStringAnsi(unitsStr, units, maxLen); } } } // !!! may produce much trace info !!! TraceCall(TraceLevel.Verbose, String.Format("{0} - {1} - {2}", result.ToString(), fieldNameStr, unitsStr)); } catch (Exception ex) { ProcessException(ex); } return((int)result); }
public override GetValueResult GetValue(string fileName, int fieldIndex, int unitIndex, int maxLen, GetValueFlags flags, out string fieldValue, out ContentFieldType fieldType) { _getAborted = false; fieldType = ContentFieldType.NoMoreFields; fieldValue = null; if (string.IsNullOrEmpty(fileName)) { return(GetValueResult.FieldEmpty); } if (fieldIndex < 0 || fieldIndex > FieldCount - 1) { return(GetValueResult.NoSuchField); } var field = Fields[fieldIndex]; if (null == field) { return(GetValueResult.NoSuchField); } fieldType = field.ContentType; var res = field.GetValue(fileName, flags, ref _getAborted); fieldValue = res.Value; return(res.Result); }
public override GetValueResult GetValue(string fileName, int fieldIndex, int unitIndex, int maxLen, GetValueFlags flags, out string fieldValue, out ContentFieldType fieldType) { GetValueResult result = GetValueResult.FieldEmpty; fieldType = ContentFieldType.NoMoreFields; fieldValue = null; if (String.IsNullOrEmpty(fileName)) { return(result); } if (Directory.Exists(fileName)) { DirectoryInfo info = new DirectoryInfo(fileName); string createdDT = info.CreationTime.ToString("G"); switch (fieldIndex) { case FileTypeIdx: fieldValue = "Folder"; fieldType = ContentFieldType.WideString; break; case Size32Idx: if ((flags & GetValueFlags.DelayIfSlow) != 0) { fieldValue = "?"; result = GetValueResult.OnDemand; } else { try { long size = GetDirectorySize(fileName); fieldType = ContentFieldType.NumericFloating; fieldValue = GetSizeValue(size); } catch (IOException) { // Directory changed, stop long operation result = GetValueResult.FieldEmpty; } } break; case CreateDateTimeIdx: fieldValue = createdDT; fieldType = ContentFieldType.DateTime; break; case CreateDateIdx: fieldValue = createdDT; fieldType = ContentFieldType.Date; break; case CreateTimeIdx: fieldValue = createdDT; fieldType = ContentFieldType.Time; break; default: result = GetValueResult.NoSuchField; break; } } else if (File.Exists(fileName)) { FileInfo info = new FileInfo(fileName); string createdDT = info.CreationTime.ToString("G"); switch (fieldIndex) { case FileTypeIdx: string fileType = String.Empty; switch (info.Extension.ToLower()) { case ".exe": case ".dll": case ".sys": case ".com": fileType = "Program"; break; case ".zip": case ".rar": case ".cab": case ".7z": fileType = "Archive"; break; case ".bmp": case ".jpg": case ".png": case ".gif": fileType = "Это Image"; break; case ".mp3": case ".avi": case ".wav": fileType = "Multimedia"; break; case ".htm": case ".html": fileType = "Web Page"; break; default: fileType = "File"; break; } if (!String.IsNullOrEmpty(fileType)) { fieldValue = fileType; fieldType = ContentFieldType.WideString; } break; case Size32Idx: long size = info.Length; fieldType = ContentFieldType.NumericFloating; fieldValue = GetSizeValue(size); break; case CreateDateTimeIdx: fieldValue = createdDT; fieldType = ContentFieldType.DateTime; break; case CreateDateIdx: fieldValue = createdDT; fieldType = ContentFieldType.Date; break; case CreateTimeIdx: fieldValue = createdDT; fieldType = ContentFieldType.Time; break; default: result = GetValueResult.NoSuchField; break; } } else { result = GetValueResult.FileError; } if (!fieldType.Equals(ContentFieldType.NoMoreFields)) { result = GetValueResult.Success; } return(result); }
// methods used in WDX plugins only public virtual SetValueResult EditValue(TcWindow parentWin, int fieldIndex, int unitIndex, ContentFieldType fieldType, ref string fieldValue, int maxLen, EditValueFlags flags, string langIdentifier) { return(SetValueResult.NoSuchField); }
public virtual SetValueResult SetValue(string fileName, int fieldIndex, int unitIndex, ContentFieldType fieldType, string fieldValue, SetValueFlags flags) { return(SetValueResult.NoSuchField); }
public virtual GetValueResult GetValue(string fileName, int fieldIndex, int unitIndex, int maxLen, GetValueFlags flags, out string fieldValue, out ContentFieldType fieldType) { throw new MethodNotSupportedException("GetValue", true); }
public ContentValue(string value, ContentFieldType fieldType) { StrValue = value; FieldType = fieldType; changed = true; }