Beispiel #1
0
        public static bool SetTimeW([MarshalAs(UnmanagedType.LPWStr)] string remoteName, IntPtr creationTime, IntPtr lastAccessTime, IntPtr lastWriteTime)
        {
            var crTime = TcUtils.ReadDateTime(creationTime);

            var laTime = TcUtils.ReadDateTime(lastAccessTime);
            var lwTime = TcUtils.ReadDateTime(lastWriteTime);

            _callSignature = $"SetTime '{remoteName}' (" +
                             (crTime.HasValue ? $" {crTime.Value:g} #" : " NULL #") +
                             (laTime.HasValue ? $" {laTime.Value:g} #" : " NULL #") +
                             (lwTime.HasValue ? $" {lwTime.Value:g} #" : " NULL #") +
                             ")";

            var result = false;

            try {
                result = Plugin.SetTime(remoteName, crTime, laTime, lwTime);

                TraceCall(TraceLevel.Info, result ? "OK" : "No");
            }
            catch (Exception ex) {
                ProcessException(ex);
            }

            return(result);
        }
Beispiel #2
0
 public RemoteInfo(IntPtr ptr)
 {
     if (ptr != IntPtr.Zero)
     {
         TcRemoteInfo data = (TcRemoteInfo)Marshal.PtrToStructure(ptr, typeof(TcRemoteInfo));
         Size          = TcUtils.GetULong(data.sizeHigh, data.sizeLow);
         LastWriteTime = TcUtils.FromFileTime(data.lastWriteTime);
         Attributes    = (FileAttributes)data.attr;
     }
 }
Beispiel #3
0
        public static int PackFilesW(
            [MarshalAs(UnmanagedType.LPWStr)] string packedFile,
            [MarshalAs(UnmanagedType.LPWStr)] string subPath,
            [MarshalAs(UnmanagedType.LPWStr)] string srcPath,
            IntPtr addListPtr, int flags)
        {
            List <string> addList = TcUtils.ReadStringListUni(addListPtr);

            return(PackFilesInternal(packedFile, subPath, srcPath, addList, (PackFilesFlags)flags));
        }
Beispiel #4
0
 public static void GetDetectString(IntPtr detectString, int maxLen)
 {
     callSignature = "GetDetectString";
     try {
         TcUtils.WriteStringAnsi(Plugin.DetectString, detectString, maxLen);
         TraceCall(TraceLevel.Warning, Plugin.DetectString);
     } catch (Exception ex) {
         ProcessException(ex);
     }
 }
Beispiel #5
0
        public static int ExecuteFileW(IntPtr mainWin, IntPtr remoteName, [MarshalAs(UnmanagedType.LPWStr)] string verb)
        {
            var rmtName = Marshal.PtrToStringUni(remoteName);
            var result  = ExecuteFileInternal(mainWin, rmtName, verb);

            if (result.Type == ExecResult.ExecEnum.SymLink && result.SymlinkTarget.HasValue)
            {
                TcUtils.WriteStringUni(result.SymlinkTarget, remoteName, 0);
            }

            return((int)result.Type);
        }
Beispiel #6
0
        public static bool GetLocalNameW(IntPtr remoteName, int maxLen)
        {
            var rmtName = Marshal.PtrToStringUni(remoteName);

            var result = GetLocalNameInternal(ref rmtName, maxLen);

            if (result)
            {
                TcUtils.WriteStringUni(rmtName, remoteName, 0);
            }

            return(result);
        }
Beispiel #7
0
        public static int GetPreviewBitmapW(IntPtr remoteName, int width, int height, IntPtr returnedBitmap)
        {
            var rmtName   = Marshal.PtrToStringUni(remoteName);
            var inRmtName = rmtName;
            var result    = GetPreviewBitmapInternal(ref rmtName, width, height, returnedBitmap);

            if (result != PreviewBitmapResult.PreviewBitmapEnum.None && !string.IsNullOrEmpty(rmtName) && !rmtName.Equals(inRmtName, StringComparison.CurrentCultureIgnoreCase))
            {
                TcUtils.WriteStringUni(rmtName, remoteName, 0);
            }

            return((int)result);
        }
Beispiel #8
0
        public static int PutFileW([MarshalAs(UnmanagedType.LPWStr)] string localName, IntPtr remoteName, int copyFlags)
        {
            var rmtName   = Marshal.PtrToStringUni(remoteName);
            var inRmtName = rmtName;
            var result    = PutFileInternal(localName, ref rmtName, (CopyFlags)copyFlags);

            if (result == FileSystemExitCode.OK && !rmtName.Equals(inRmtName, StringComparison.CurrentCultureIgnoreCase))
            {
                TcUtils.WriteStringUni(rmtName, remoteName, 0);
            }

            return((int)result);
        }
Beispiel #9
0
        public static int GetFile([MarshalAs(UnmanagedType.LPStr)] string remoteName, IntPtr localName, int copyFlags, IntPtr remoteInfo)
        {
            var locName   = Marshal.PtrToStringAnsi(localName);
            var inLocName = locName;
            var result    = GetFileInternal(remoteName, ref locName, (CopyFlags)copyFlags, remoteInfo);

            if (result == FileSystemExitCode.OK && !locName.Equals(inLocName, StringComparison.CurrentCultureIgnoreCase))
            {
                TcUtils.WriteStringAnsi(locName, localName, 0);
            }

            return((int)result);
        }
Beispiel #10
0
        public static void GetDefRootName(IntPtr rootName, int maxLen)
        {
            _callSignature = "GetDefRootName";
            try {
                TcUtils.WriteStringAnsi(Plugin.Title, rootName, maxLen);

                TraceCall(TraceLevel.Warning, Plugin.Title);
            }
            catch (Exception ex) {
                TcUtils.WriteStringAnsi(ex.Message, rootName, maxLen);
                ProcessException(ex);
            }
        }
Beispiel #11
0
        public static int ExtractCustomIconW(IntPtr remoteName, int extractFlags, IntPtr theIcon)
        {
            var rmtName   = Marshal.PtrToStringUni(remoteName);
            var inRmtName = rmtName;
            var result    = ExtractIconInternal(ref rmtName, extractFlags, theIcon);

            if (result != ExtractIconResult.ExtractIconEnum.UseDefault && !rmtName.Equals(inRmtName, StringComparison.CurrentCultureIgnoreCase))
            {
                TcUtils.WriteStringUni(rmtName, remoteName, 0);
            }

            return((int)result);
        }
Beispiel #12
0
        //public int UnpVer { get; set; }
        //public int Method { get; set; }

        //   may be used in the future
        //public string CmtBuf { get; set; }
        //public int CmtBufSize { get; set; }
        //public int CmtSize { get; set; }
        //public int CmtState { get; set; }
        //public string Reserved { get; set; }

        #endregion Properties

        public void CopyTo(IntPtr ptr, HeaderDataMode mode)
        {
            if (ptr != IntPtr.Zero)
            {
                if (mode == HeaderDataMode.Ansi)
                {
                    var data = new TcHeaderData {
                        ArchiveName = ArchiveName,
                        FileName    = FileName,
                        FileAttr    = ((int)FileAttributes) & AllowedPackerAttributes,
                        FileCRC     = FileCRC,
                        FileTime    = TcUtils.GetArchiveHeaderTime(FileTime),
                        PackSize    = (int)PackedSize,
                        UnpSize     = (int)UnpackedSize
                    };
                    Marshal.StructureToPtr(data, ptr, false);
                }
                else if (mode == HeaderDataMode.ExAnsi)
                {
                    var data = new TcHeaderDataEx {
                        ArchiveName  = ArchiveName,
                        FileName     = FileName,
                        FileAttr     = ((int)FileAttributes) & AllowedPackerAttributes,
                        FileCRC      = FileCRC,
                        FileTime     = TcUtils.GetArchiveHeaderTime(FileTime),
                        PackSizeHigh = TcUtils.GetUHigh(PackedSize),
                        PackSizeLow  = TcUtils.GetULow(PackedSize),
                        UnpSizeHigh  = TcUtils.GetUHigh(UnpackedSize),
                        UnpSizeLow   = TcUtils.GetULow(UnpackedSize)
                    };
                    Marshal.StructureToPtr(data, ptr, false);
                }
                else if (mode == HeaderDataMode.ExUnicode)
                {
                    var data = new TcHeaderDataExW {
                        ArchiveName  = ArchiveName,
                        FileName     = FileName,
                        FileAttr     = ((int)FileAttributes) & AllowedPackerAttributes,
                        FileCRC      = FileCRC,
                        FileTime     = TcUtils.GetArchiveHeaderTime(FileTime),
                        PackSizeHigh = TcUtils.GetUHigh(PackedSize),
                        PackSizeLow  = TcUtils.GetULow(PackedSize),
                        UnpSizeHigh  = TcUtils.GetUHigh(UnpackedSize),
                        UnpSizeLow   = TcUtils.GetULow(UnpackedSize)
                    };
                    Marshal.StructureToPtr(data, ptr, false);
                }
            }
        }
Beispiel #13
0
        public static bool GetDefaultViewW(IntPtr viewContents, IntPtr viewHeaders, IntPtr viewWidths, IntPtr viewOptions, int maxLen)
        {
            var result = GetDefaultViewFs(out var contents, out var headers, out var widths, out var options, maxLen);

            if (result)
            {
                TcUtils.WriteStringUni(contents, viewContents, maxLen);
                TcUtils.WriteStringUni(headers, viewHeaders, maxLen);
                TcUtils.WriteStringUni(widths, viewWidths, maxLen);
                TcUtils.WriteStringUni(options, viewOptions, maxLen);

                return(true);
            }

            return(false);
        }
Beispiel #14
0
        public static int GetSupportedField(int fieldIndex, IntPtr fieldName, IntPtr units, int maxLen)
        {
            var result = ContentFieldType.NoMoreFields;

            _callSignature = $"ContentGetSupportedField ({fieldIndex})";
            try {
                if (ContentPlugin != null)
                {
                    result = ContentPlugin.GetSupportedField(fieldIndex, out var fieldNameStr, out var 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, $"{result.ToString()} - {fieldNameStr} - {unitsStr}");
                }
            }
            catch (Exception ex) {
                ProcessException(ex);
            }

            return((int)result);
        }
Beispiel #15
0
 public void CopyTo(IntPtr ptr, bool isUnicode)
 {
     if (ptr != IntPtr.Zero)
     {
         if (isUnicode)
         {
             var data = new TcFindDataW {
                 FileAttributes    = (int)Attributes,
                 CreationTime      = TcUtils.GetFileTime(CreationTime),
                 LastAccessTime    = TcUtils.GetFileTime(LastAccessTime),
                 LastWriteTime     = TcUtils.GetFileTime(LastWriteTime),
                 FileSizeHigh      = TcUtils.GetUHigh(FileSize),
                 FileSizeLow       = TcUtils.GetULow(FileSize),
                 Reserved0         = Reserved0,
                 Reserved1         = Reserved1,
                 FileName          = FileName,
                 AlternateFileName = string.Empty
             };
             Marshal.StructureToPtr(data, ptr, false);
         }
         else
         {
             var data = new TcFindData {
                 FileAttributes    = (int)Attributes,
                 CreationTime      = TcUtils.GetFileTime(CreationTime),
                 LastAccessTime    = TcUtils.GetFileTime(LastAccessTime),
                 LastWriteTime     = TcUtils.GetFileTime(LastWriteTime),
                 FileSizeHigh      = TcUtils.GetUHigh(FileSize),
                 FileSizeLow       = TcUtils.GetULow(FileSize),
                 Reserved0         = Reserved0,
                 Reserved1         = Reserved1,
                 FileName          = FileName,
                 AlternateFileName = string.Empty
             };
             Marshal.StructureToPtr(data, ptr, false);
         }
     }
 }
Beispiel #16
0
        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);
        }
Beispiel #17
0
        public void CopyTo(IntPtr ptr)
        {
            if (ptr != IntPtr.Zero && changed)
            {
                switch (FieldType)
                {
                case ContentFieldType.Numeric32:
                    Marshal.WriteInt32(ptr, Int32.Parse(strValue));
                    break;

                case ContentFieldType.Numeric64:
                    Marshal.WriteInt64(ptr, Int64.Parse(strValue));
                    break;

                case ContentFieldType.NumericFloating:
                    string altStr   = null;
                    string floatStr = strValue;
                    if (floatStr.Contains("|"))
                    {
                        int pos = floatStr.IndexOf("|", StringComparison.Ordinal);
                        altStr   = floatStr.Substring(pos + 1);
                        floatStr = floatStr.Substring(0, pos);
                    }
                    Marshal.Copy(new[] { Double.Parse(floatStr) }, 0, ptr, 1);
                    if (!String.IsNullOrEmpty(altStr))
                    {
                        // ??? ANSI or Unicode
                        IntPtr altOutput = new IntPtr(ptr.ToInt32() + sizeof(Double));
                        Marshal.Copy((altStr + (Char)0).ToCharArray(), 0, altOutput, altStr.Length + 1);
                    }
                    break;

                case ContentFieldType.Date:
                    DateTime date = DateTime.Parse(strValue);
                    Marshal.Copy(new[] { (Int16)date.Year, (Int16)date.Month, (Int16)date.Day }, 0, ptr, 3);
                    break;

                case ContentFieldType.Time:
                    DateTime time = DateTime.Parse(strValue);
                    Marshal.Copy(new[] { (Int16)time.Hour, (Int16)time.Minute, (Int16)time.Second }, 0, ptr, 3);
                    break;

                case ContentFieldType.Boolean:
                    Marshal.WriteInt32(ptr, Boolean.Parse(strValue) ? 1 : 0);
                    break;

                case ContentFieldType.MultipleChoice:
                case ContentFieldType.String:
                    TcUtils.WriteStringAnsi(strValue, ptr, 0);
                    break;

                case ContentFieldType.FullText:
                    // ??? can it be Unicode ???
                    TcUtils.WriteStringAnsi(strValue, ptr, 0);
                    break;

                case ContentFieldType.DateTime:
                    Marshal.WriteInt64(ptr, DateTime.Parse(strValue).ToFileTime());
                    break;

                case ContentFieldType.WideString:
                    TcUtils.WriteStringUni(strValue, ptr, 0);
                    break;
                }
            }
        }
Beispiel #18
0
        public static int DeleteFilesW([MarshalAs(UnmanagedType.LPWStr)] string packedFile, IntPtr deleteListPtr)
        {
            List <string> deleteList = TcUtils.ReadStringListUni(deleteListPtr);

            return(DeleteFilesInternal(packedFile, deleteList));
        }
Beispiel #19
0
        public static void FsRequestCallback(RequestEventArgs e)
        {
            if (requestCallbackW != null || requestCallback != null)
            {
                var retText = IntPtr.Zero;
                if (e.RequestType < (int)RequestType.MsgOk)
                {
                    if (requestCallbackW != null)
                    {
                        retText = Marshal.AllocHGlobal(e.MaxLen * 2);
                        Marshal.Copy(new char[e.MaxLen], 0, retText, e.MaxLen);
                    }
                    else
                    {
                        retText = Marshal.AllocHGlobal(e.MaxLen);
                        Marshal.Copy(new byte[e.MaxLen], 0, retText, e.MaxLen);
                    }
                }

                try {
                    if (retText != IntPtr.Zero && !string.IsNullOrEmpty(e.ReturnedText))
                    {
                        if (requestCallbackW != null)
                        {
                            Marshal.Copy(e.ReturnedText.ToCharArray(), 0, retText, e.ReturnedText.Length);
                        }
                        else
                        {
                            TcUtils.WriteStringAnsi(e.ReturnedText, retText, 0);
                        }
                    }

                    if (requestCallbackW != null)
                    {
                        e.Result = requestCallbackW(e.PluginNumber, e.RequestType, e.CustomTitle, e.CustomText, retText, e.MaxLen) ? 1 : 0;
                    }
                    else
                    {
                        e.Result = requestCallback(e.PluginNumber, e.RequestType, e.CustomTitle, e.CustomText, retText, e.MaxLen) ? 1 : 0;
                    }
#if TRACE
                    var traceStr = $"OnRequest ({e.PluginNumber}, {(RequestType) e.RequestType}): {e.ReturnedText}";
#endif
                    if (e.Result != 0 && retText != IntPtr.Zero)
                    {
                        e.ReturnedText = (requestCallbackW != null) ? Marshal.PtrToStringUni(retText) : Marshal.PtrToStringAnsi(retText);
#if TRACE
                        traceStr += " => " + e.ReturnedText;
#endif
                    }
#if TRACE
                    TraceOut(TraceLevel.Verbose, $"{traceStr} - {e.Result}.", Callback);
#endif
                }
                finally {
                    if (retText != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(retText);
                    }
                }
            }
        }
Beispiel #20
0
        public static void FsRequestCallback(RequestEventArgs e)
        {
            if (e.RequestType == (int)RequestType.DomainInfo)
            {
                e.ReturnedText = TcPluginLoader.DomainInfo;
                e.Result       = 1;
#if TRACE
                TraceOut(TraceLevel.Info, e.ReturnedText, TraceMsg4);
#endif
            }
            else if (requestCallbackW != null || requestCallback != null)
            {
                IntPtr retText = IntPtr.Zero;
                if (e.RequestType < (int)RequestType.MsgOk)
                {
                    if (requestCallbackW != null)
                    {
                        retText = Marshal.AllocHGlobal(e.MaxLen * 2);
                        Marshal.Copy(new char[e.MaxLen], 0, retText, e.MaxLen);
                    }
                    else
                    {
                        retText = Marshal.AllocHGlobal(e.MaxLen);
                        Marshal.Copy(new byte[e.MaxLen], 0, retText, e.MaxLen);
                    }
                }
                try {
                    if (retText != IntPtr.Zero && !String.IsNullOrEmpty(e.ReturnedText))
                    {
                        if (requestCallbackW != null)
                        {
                            Marshal.Copy(e.ReturnedText.ToCharArray(), 0, retText, e.ReturnedText.Length);
                        }
                        else
                        {
                            TcUtils.WriteStringAnsi(e.ReturnedText, retText, 0);
                        }
                    }
                    if (requestCallbackW != null)
                    {
                        e.Result = requestCallbackW(e.PluginNumber, e.RequestType, e.CustomTitle, e.CustomText, retText, e.MaxLen) ? 1 : 0;
                    }
                    else
                    {
                        e.Result = requestCallback(e.PluginNumber, e.RequestType, e.CustomTitle, e.CustomText, retText, e.MaxLen) ? 1 : 0;
                    }
#if TRACE
                    string traceStr = String.Format(TraceMsg5, e.PluginNumber, ((RequestType)e.RequestType).ToString(), e.ReturnedText);
#endif
                    if (e.Result != 0 && retText != IntPtr.Zero)
                    {
                        e.ReturnedText = (requestCallbackW != null) ?
                                         Marshal.PtrToStringUni(retText) : Marshal.PtrToStringAnsi(retText);
#if TRACE
                        traceStr += " => " + e.ReturnedText;
#endif
                    }
#if TRACE
                    TraceOut(TraceLevel.Verbose, String.Format(TraceMsg7, traceStr, e.Result), TraceMsg1);
#endif
                } finally {
                    if (retText != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(retText);
                    }
                }
            }
        }